Skip to content

Commit

Permalink
Add brotli decoding support
Browse files Browse the repository at this point in the history
  • Loading branch information
exogen committed Apr 13, 2021
1 parent 6fbddc7 commit 2dd9b22
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 28 deletions.
2 changes: 2 additions & 0 deletions src/encoding.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ import zlib from 'zlib';
import createLogger from 'debug';

const debug = createLogger('ava-nock:encoding');

const decoders = new Map([
['gzip', zlib.gunzip],
['deflate', zlib.inflate],
['br', zlib.brotliDecompress],
]);

function findLastEncoding(headers) {
Expand Down
26 changes: 13 additions & 13 deletions test/snapshots/axios.test.js.nock
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"path": "/ws/2/artist/c8da2e40-bd28-4d4e-813a-bd2f51958ba8?secretKey=*",
"rawHeaders": [
"Date",
"Tue, 13 Apr 2021 03:21:06 GMT",
"Tue, 13 Apr 2021 07:38:56 GMT",
"Content-Type",
"application/json; charset=utf-8",
"Content-Length",
Expand All @@ -20,13 +20,13 @@
"X-RateLimit-Limit",
"1200",
"X-RateLimit-Remaining",
"778",
"900",
"X-RateLimit-Reset",
"1618284066",
"1618299537",
"Server",
"Plack::Handler::Starlet",
"ETag",
"\"377e27db5d6792ea9bee8ba33b356935\"",
"\"af00009d7f51d3fe6f04fcae93f06936\"",
"Access-Control-Allow-Origin",
"*",
"X-Cache-Status",
Expand Down Expand Up @@ -97,7 +97,7 @@
"path": "/ws/2/artist/5b11f4ce-a62d-471e-81fc-a69a8278c7da?fmt=json",
"rawHeaders": [
"Date",
"Tue, 13 Apr 2021 03:21:04 GMT",
"Tue, 13 Apr 2021 07:38:55 GMT",
"Content-Type",
"application/json; charset=utf-8",
"Content-Length",
Expand All @@ -109,17 +109,17 @@
"X-RateLimit-Limit",
"1200",
"X-RateLimit-Remaining",
"1123",
"671",
"X-RateLimit-Reset",
"1618284066",
"1618299535",
"Server",
"Plack::Handler::Starlet",
"ETag",
"\"50375d569b8abc25bb65c37002929693\"",
"\"a821be67d4dc50e6690dfe859be7cfd8\"",
"Access-Control-Allow-Origin",
"*",
"X-Cache-Status",
"UPDATING"
"MISS"
],
"reqheaders": {
"accept": "application/json, text/plain, */*",
Expand Down Expand Up @@ -191,7 +191,7 @@
"path": "/ws/2/artist/5b11f4ce-a62d-471e-81fc-a69a8278c7da?fmt=xml",
"rawHeaders": [
"Date",
"Tue, 13 Apr 2021 03:21:05 GMT",
"Tue, 13 Apr 2021 07:38:56 GMT",
"Content-Type",
"application/xml; charset=utf-8",
"Transfer-Encoding",
Expand All @@ -203,17 +203,17 @@
"X-RateLimit-Limit",
"1200",
"X-RateLimit-Remaining",
"922",
"1077",
"X-RateLimit-Reset",
"1618284066",
"1618299537",
"Server",
"Plack::Handler::Starlet",
"ETag",
"\"7baabb90f872d8f2e6a89774d80a93a7\"",
"Access-Control-Allow-Origin",
"*",
"X-Cache-Status",
"STALE"
"MISS"
],
"reqheaders": {
"accept": "application/json, text/plain, */*",
Expand Down
20 changes: 10 additions & 10 deletions test/snapshots/fetch.test.js.nock
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"path": "/ws/2/artist/5b11f4ce-a62d-471e-81fc-a69a8278c7da?fmt=json",
"rawHeaders": [
"Date",
"Tue, 13 Apr 2021 03:21:04 GMT",
"Tue, 13 Apr 2021 07:38:55 GMT",
"Content-Type",
"application/json; charset=utf-8",
"Transfer-Encoding",
Expand All @@ -25,17 +25,17 @@
"X-RateLimit-Limit",
"1200",
"X-RateLimit-Remaining",
"1126",
"672",
"X-RateLimit-Reset",
"1618284066",
"1618299535",
"Server",
"Plack::Handler::Starlet",
"ETag",
"W/\"50375d569b8abc25bb65c37002929693\"",
"W/\"c478da8c0e205ef3673fc15ee551c155\"",
"Access-Control-Allow-Origin",
"*",
"X-Cache-Status",
"STALE"
"MISS"
],
"reqheaders": {
"accept": [
Expand All @@ -49,7 +49,7 @@
],
"host": "musicbrainz.org"
},
"response": "{\"ipis\":[],\"type\":\"Group\",\"area\":{\"disambiguation\":\"\",\"iso-3166-1-codes\":[\"US\"],\"type-id\":null,\"sort-name\":\"United States\",\"id\":\"489ce91b-6658-3307-9877-795b68554c98\",\"name\":\"United States\",\"type\":null},\"end_area\":null,\"begin-area\":{\"sort-name\":\"Aberdeen\",\"type-id\":null,\"id\":\"a640b45c-c173-49b1-8030-973603e895b5\",\"name\":\"Aberdeen\",\"type\":null,\"disambiguation\":\"\"},\"end-area\":null,\"sort-name\":\"Nirvana\",\"name\":\"Nirvana\",\"gender\":null,\"isnis\":[\"0000000123486830\",\"0000000123487390\"],\"gender-id\":null,\"disambiguation\":\"90s US grunge band\",\"country\":\"US\",\"begin_area\":{\"sort-name\":\"Aberdeen\",\"type-id\":null,\"id\":\"a640b45c-c173-49b1-8030-973603e895b5\",\"name\":\"Aberdeen\",\"type\":null,\"disambiguation\":\"\"},\"type-id\":\"e431f5f6-b5d2-343d-8b36-72607fffb74b\",\"id\":\"5b11f4ce-a62d-471e-81fc-a69a8278c7da\",\"life-span\":{\"begin\":\"1988-01\",\"ended\":true,\"end\":\"1994-04-05\"}}",
"response": "{\"disambiguation\":\"90s US grunge band\",\"ipis\":[],\"begin-area\":{\"sort-name\":\"Aberdeen\",\"type\":null,\"id\":\"a640b45c-c173-49b1-8030-973603e895b5\",\"type-id\":null,\"disambiguation\":\"\",\"name\":\"Aberdeen\"},\"type\":\"Group\",\"isnis\":[\"0000000123486830\",\"0000000123487390\"],\"gender-id\":null,\"gender\":null,\"country\":\"US\",\"id\":\"5b11f4ce-a62d-471e-81fc-a69a8278c7da\",\"type-id\":\"e431f5f6-b5d2-343d-8b36-72607fffb74b\",\"life-span\":{\"begin\":\"1988-01\",\"ended\":true,\"end\":\"1994-04-05\"},\"sort-name\":\"Nirvana\",\"end-area\":null,\"name\":\"Nirvana\",\"begin_area\":{\"sort-name\":\"Aberdeen\",\"type\":null,\"id\":\"a640b45c-c173-49b1-8030-973603e895b5\",\"type-id\":null,\"disambiguation\":\"\",\"name\":\"Aberdeen\"},\"end_area\":null,\"area\":{\"type-id\":null,\"id\":\"489ce91b-6658-3307-9877-795b68554c98\",\"iso-3166-1-codes\":[\"US\"],\"disambiguation\":\"\",\"name\":\"United States\",\"type\":null,\"sort-name\":\"United States\"}}",
"responseIsBinary": false,
"scope": "https://musicbrainz.org:443",
"status": 200
Expand All @@ -65,7 +65,7 @@
"path": "/ws/2/artist/5b11f4ce-a62d-471e-81fc-a69a8278c7da",
"rawHeaders": [
"Date",
"Tue, 13 Apr 2021 03:21:05 GMT",
"Tue, 13 Apr 2021 07:38:56 GMT",
"Content-Type",
"application/xml; charset=utf-8",
"Transfer-Encoding",
Expand All @@ -77,17 +77,17 @@
"X-RateLimit-Limit",
"1200",
"X-RateLimit-Remaining",
"928",
"1075",
"X-RateLimit-Reset",
"1618284066",
"1618299537",
"Server",
"Plack::Handler::Starlet",
"ETag",
"W/\"7baabb90f872d8f2e6a89774d80a93a7\"",
"Access-Control-Allow-Origin",
"*",
"X-Cache-Status",
"STALE"
"MISS"
],
"reqheaders": {
"accept": [
Expand Down
10 changes: 5 additions & 5 deletions test/snapshots/request.test.js.nock
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"path": "/ws/2/artist/5b11f4ce-a62d-471e-81fc-a69a8278c7da?fmt=json",
"rawHeaders": [
"Date",
"Tue, 13 Apr 2021 03:21:04 GMT",
"Tue, 13 Apr 2021 07:38:55 GMT",
"Content-Type",
"application/json; charset=utf-8",
"Content-Length",
Expand All @@ -20,17 +20,17 @@
"X-RateLimit-Limit",
"1200",
"X-RateLimit-Remaining",
"1124",
"650",
"X-RateLimit-Reset",
"1618284066",
"1618299535",
"Server",
"Plack::Handler::Starlet",
"ETag",
"\"50375d569b8abc25bb65c37002929693\"",
"\"a821be67d4dc50e6690dfe859be7cfd8\"",
"Access-Control-Allow-Origin",
"*",
"X-Cache-Status",
"UPDATING"
"HIT"
],
"reqheaders": {
"host": "musicbrainz.org"
Expand Down

0 comments on commit 2dd9b22

Please sign in to comment.