From f5980cf73c8c1adbb143a12bf83864c835592005 Mon Sep 17 00:00:00 2001 From: Offir Golan Date: Tue, 26 Jun 2018 19:36:49 -0700 Subject: [PATCH] fix(core): Set `url` on the fetch Response object (#44) Resolved #43. --- .../@pollyjs/core/src/adapters/fetch/index.js | 20 +- packages/@pollyjs/ember/yarn.lock | 190 +----------------- 2 files changed, 23 insertions(+), 187 deletions(-) diff --git a/packages/@pollyjs/core/src/adapters/fetch/index.js b/packages/@pollyjs/core/src/adapters/fetch/index.js index 5c0e4892..bc52ca66 100644 --- a/packages/@pollyjs/core/src/adapters/fetch/index.js +++ b/packages/@pollyjs/core/src/adapters/fetch/index.js @@ -1,7 +1,9 @@ import Adapter from '@pollyjs/adapter'; import serializeHeaders from './utils/serialize-headers'; +import URL from 'url-parse'; const nativeFetch = self.fetch; +const { defineProperty } = Object; export default class FetchAdapter extends Adapter { onConnect() { @@ -68,12 +70,26 @@ export default class FetchAdapter extends Adapter { async respond(pollyRequest, status, headers, body) { await pollyRequest.respond(status, headers, body); - const { response } = pollyRequest; + const { url, response } = pollyRequest; - return new Response(response.body, { + const fetchResponse = new Response(response.body, { status: response.statusCode, headers: response.headers }); + + /* + Response does not allow `url` to be set manually (either via the + constructor or assignment) so force the url property via `defineProperty`. + */ + defineProperty(fetchResponse, 'url', { + /* + Since `url` can be a relative url and Response always has an absolute + one, use URL to attach the host if necessary. + */ + value: new URL(url).href + }); + + return fetchResponse; } toString() { diff --git a/packages/@pollyjs/ember/yarn.lock b/packages/@pollyjs/ember/yarn.lock index a9f3f96a..f07a2b64 100644 --- a/packages/@pollyjs/ember/yarn.lock +++ b/packages/@pollyjs/ember/yarn.lock @@ -20,61 +20,6 @@ dependencies: "@glimmer/di" "^0.2.0" -"@pollyjs/adapter@^0.3.0": - version "0.3.0" - resolved "https://registry.yarnpkg.com/@pollyjs/adapter/-/adapter-0.3.0.tgz#e8f0f6cd7d86b416277fd4bb223b9639eee2ec3e" - dependencies: - "@pollyjs/utils" "^0.1.0" - -"@pollyjs/core@^0.4.0": - version "0.4.0" - resolved "https://registry.yarnpkg.com/@pollyjs/core/-/core-0.4.0.tgz#99cbe52cd7a83bbc6bbb477a4777c917fd1e6eb6" - dependencies: - "@pollyjs/adapter" "^0.3.0" - "@pollyjs/persister" "^0.2.0" - "@pollyjs/utils" "^0.1.0" - "@sindresorhus/fnv1a" "^1.0.0" - blueimp-md5 "^2.10.0" - is-absolute-url "^2.1.0" - json-stable-stringify "^1.0.1" - lodash-es "^4.17.10" - merge-options "^1.0.1" - nise "^1.4.1" - route-recognizer "^0.3.3" - slugify "^1.3.0" - url-parse "^1.4.1" - -"@pollyjs/node-server@^0.2.0": - version "0.2.0" - resolved "https://registry.yarnpkg.com/@pollyjs/node-server/-/node-server-0.2.0.tgz#10b33ae68553b5a10baa99afa627f51a49554be6" - dependencies: - body-parser "^1.18.3" - express "^4.16.3" - fs-extra "^5.0.0" - http-graceful-shutdown "^2.1.1" - morgan "^1.9.0" - nocache "^2.0.0" - -"@pollyjs/persister@^0.2.0": - version "0.2.0" - resolved "https://registry.yarnpkg.com/@pollyjs/persister/-/persister-0.2.0.tgz#4fe2cd0bab40d3b8e3e1712da775f4728e716806" - dependencies: - "@pollyjs/utils" "^0.1.0" - -"@pollyjs/utils@^0.1.0": - version "0.1.0" - resolved "https://registry.yarnpkg.com/@pollyjs/utils/-/utils-0.1.0.tgz#e64d92e8becd05cf3b145b1f88da559b5cbd6f79" - -"@sindresorhus/fnv1a@^1.0.0": - version "1.0.0" - resolved "https://registry.yarnpkg.com/@sindresorhus/fnv1a/-/fnv1a-1.0.0.tgz#d419dd111b4d7fc3b87f97d86849bc23316149de" - -"@sinonjs/formatio@^2.0.0": - version "2.0.0" - resolved "https://registry.yarnpkg.com/@sinonjs/formatio/-/formatio-2.0.0.tgz#84db7e9eb5531df18a8c5e0bfb6e449e55e654b2" - dependencies: - samsam "1.3.0" - abbrev@1: version "1.1.1" resolved "https://registry.yarnpkg.com/abbrev/-/abbrev-1.1.1.tgz#f8f2c887ad10bf67f634f005b6987fed3179aac8" @@ -938,10 +883,6 @@ bluebird@^3.1.1, bluebird@^3.4.6: version "3.5.1" resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-3.5.1.tgz#d9551f9de98f1fcda1e683d17ee91a0602ee2eb9" -blueimp-md5@^2.10.0: - version "2.10.0" - resolved "https://registry.yarnpkg.com/blueimp-md5/-/blueimp-md5-2.10.0.tgz#02f0843921f90dca14f5b8920a38593201d6964d" - body-parser@1.18.2: version "1.18.2" resolved "https://registry.yarnpkg.com/body-parser/-/body-parser-1.18.2.tgz#87678a19d84b47d859b83199bd59bce222b10454" @@ -957,21 +898,6 @@ body-parser@1.18.2: raw-body "2.3.2" type-is "~1.6.15" -body-parser@^1.18.3: - version "1.18.3" - resolved "https://registry.yarnpkg.com/body-parser/-/body-parser-1.18.3.tgz#5b292198ffdd553b3a0f20ded0592b956955c8b4" - dependencies: - bytes "3.0.0" - content-type "~1.0.4" - debug "2.6.9" - depd "~1.1.2" - http-errors "~1.6.3" - iconv-lite "0.4.23" - on-finished "~2.3.0" - qs "6.5.2" - raw-body "2.3.3" - type-is "~1.6.16" - body@^5.1.0: version "5.1.0" resolved "https://registry.yarnpkg.com/body/-/body-5.1.0.tgz#e4ba0ce410a46936323367609ecb4e6553125069" @@ -2714,7 +2640,7 @@ expand-tilde@^2.0.0, expand-tilde@^2.0.2: dependencies: homedir-polyfill "^1.0.1" -express@^4.10.7, express@^4.12.3, express@^4.16.3: +express@^4.10.7, express@^4.12.3: version "4.16.3" resolved "https://registry.yarnpkg.com/express/-/express-4.16.3.tgz#6af8a502350db3246ecc4becf6b5a34d22f7ed53" dependencies: @@ -3058,14 +2984,6 @@ fs-extra@^4.0.0: jsonfile "^4.0.0" universalify "^0.1.0" -fs-extra@^5.0.0: - version "5.0.0" - resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-5.0.0.tgz#414d0110cdd06705734d055652c5411260c31abd" - dependencies: - graceful-fs "^4.1.2" - jsonfile "^4.0.0" - universalify "^0.1.0" - fs-tree-diff@^0.5.2, fs-tree-diff@^0.5.3, fs-tree-diff@^0.5.4, fs-tree-diff@^0.5.6: version "0.5.7" resolved "https://registry.yarnpkg.com/fs-tree-diff/-/fs-tree-diff-0.5.7.tgz#315e2b098d5fe7f622880ac965b1b051868ac871" @@ -3426,7 +3344,7 @@ http-errors@1.6.2: setprototypeof "1.0.3" statuses ">= 1.3.1 < 2" -http-errors@1.6.3, http-errors@~1.6.2, http-errors@~1.6.3: +http-errors@~1.6.2: version "1.6.3" resolved "https://registry.yarnpkg.com/http-errors/-/http-errors-1.6.3.tgz#8b55680bb4be283a0b5bf4ea2e38580be1d9320d" dependencies: @@ -3435,12 +3353,6 @@ http-errors@1.6.3, http-errors@~1.6.2, http-errors@~1.6.3: setprototypeof "1.1.0" statuses ">= 1.4.0 < 2" -http-graceful-shutdown@^2.1.1: - version "2.1.1" - resolved "https://registry.yarnpkg.com/http-graceful-shutdown/-/http-graceful-shutdown-2.1.1.tgz#915a3b3f89e6d68f438390f66eeb055aab2bf6a0" - dependencies: - debug "^3.1.0" - http-parser-js@>=0.4.0: version "0.4.11" resolved "https://registry.yarnpkg.com/http-parser-js/-/http-parser-js-0.4.11.tgz#5b720849c650903c27e521633d94696ee95f3529" @@ -3464,12 +3376,6 @@ iconv-lite@0.4.19: version "0.4.19" resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.19.tgz#f7468f60135f5e5dad3399c0a81be9a1603a082b" -iconv-lite@0.4.23: - version "0.4.23" - resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.23.tgz#297871f63be507adcfbfca715d0cd0eed84e9a63" - dependencies: - safer-buffer ">= 2.1.2 < 3" - iconv-lite@^0.4.17, iconv-lite@~0.4.13: version "0.4.21" resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.21.tgz#c47f8733d02171189ebc4a400f3218d348094798" @@ -3571,10 +3477,6 @@ ipaddr.js@1.6.0: version "1.6.0" resolved "https://registry.yarnpkg.com/ipaddr.js/-/ipaddr.js-1.6.0.tgz#e3fa357b773da619f26e95f049d055c72796f86b" -is-absolute-url@^2.1.0: - version "2.1.0" - resolved "https://registry.yarnpkg.com/is-absolute-url/-/is-absolute-url-2.1.0.tgz#50530dfb84fcc9aa7dbe7852e83a37b93b9f2aa6" - is-accessor-descriptor@^0.1.6: version "0.1.6" resolved "https://registry.yarnpkg.com/is-accessor-descriptor/-/is-accessor-descriptor-0.1.6.tgz#a9e12cb3ae8d876727eeef3843f8a0897b5c98d6" @@ -3745,10 +3647,6 @@ is-path-inside@^1.0.0: dependencies: path-is-inside "^1.0.1" -is-plain-obj@^1.1: - version "1.1.0" - resolved "https://registry.yarnpkg.com/is-plain-obj/-/is-plain-obj-1.1.0.tgz#71a50c8429dfca773c92a390a4a03b39fcd51d3e" - is-plain-object@^2.0.1, is-plain-object@^2.0.3, is-plain-object@^2.0.4: version "2.0.4" resolved "https://registry.yarnpkg.com/is-plain-object/-/is-plain-object-2.0.4.tgz#2c163b3fafb1b606d9d17928f05c2a1c38e07677" @@ -3943,10 +3841,6 @@ jsprim@^1.2.2: json-schema "0.2.3" verror "1.10.0" -just-extend@^1.1.27: - version "1.1.27" - resolved "https://registry.yarnpkg.com/just-extend/-/just-extend-1.1.27.tgz#ec6e79410ff914e472652abfa0e603c03d60e905" - kind-of@^3.0.2, kind-of@^3.0.3, kind-of@^3.2.0: version "3.2.2" resolved "https://registry.yarnpkg.com/kind-of/-/kind-of-3.2.2.tgz#31ea21a734bab9bbb0f32466d893aea51e4a3c64" @@ -4032,10 +3926,6 @@ locate-path@^2.0.0: p-locate "^2.0.0" path-exists "^3.0.0" -lodash-es@^4.17.10: - version "4.17.10" - resolved "https://registry.yarnpkg.com/lodash-es/-/lodash-es-4.17.10.tgz#62cd7104cdf5dd87f235a837f0ede0e8e5117e05" - lodash._baseassign@^3.0.0: version "3.2.0" resolved "https://registry.yarnpkg.com/lodash._baseassign/-/lodash._baseassign-3.2.0.tgz#8c38a099500f215ad09e59f1722fd0c52bfe0a4e" @@ -4373,10 +4263,6 @@ log-symbols@^2.2.0: dependencies: chalk "^2.0.1" -lolex@^2.3.2: - version "2.7.0" - resolved "https://registry.yarnpkg.com/lolex/-/lolex-2.7.0.tgz#9c087a69ec440e39d3f796767cf1b2cdc43d5ea5" - longest@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/longest/-/longest-1.0.1.tgz#30a0b2da38f73770e8294a0d22e6625ed77d0097" @@ -4508,12 +4394,6 @@ merge-descriptors@1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/merge-descriptors/-/merge-descriptors-1.0.1.tgz#b00aaa556dd8b44568150ec9d1b953f3f90cbb61" -merge-options@^1.0.1: - version "1.0.1" - resolved "https://registry.yarnpkg.com/merge-options/-/merge-options-1.0.1.tgz#2a64b24457becd4e4dc608283247e94ce589aa32" - dependencies: - is-plain-obj "^1.1" - merge-trees@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/merge-trees/-/merge-trees-1.0.1.tgz#ccbe674569787f9def17fd46e6525f5700bbd23e" @@ -4629,7 +4509,7 @@ mktemp@~0.4.0: version "0.4.0" resolved "https://registry.yarnpkg.com/mktemp/-/mktemp-0.4.0.tgz#6d0515611c8a8c84e484aa2000129b98e981ff0b" -morgan@^1.8.1, morgan@^1.9.0: +morgan@^1.8.1: version "1.9.0" resolved "https://registry.yarnpkg.com/morgan/-/morgan-1.9.0.tgz#d01fa6c65859b76fcf31b3cb53a3821a311d8051" dependencies: @@ -4692,26 +4572,12 @@ nice-try@^1.0.4: version "1.0.4" resolved "https://registry.yarnpkg.com/nice-try/-/nice-try-1.0.4.tgz#d93962f6c52f2c1558c0fbda6d512819f1efe1c4" -nise@^1.4.1: - version "1.4.2" - resolved "https://registry.yarnpkg.com/nise/-/nise-1.4.2.tgz#a9a3800e3994994af9e452333d549d60f72b8e8c" - dependencies: - "@sinonjs/formatio" "^2.0.0" - just-extend "^1.1.27" - lolex "^2.3.2" - path-to-regexp "^1.7.0" - text-encoding "^0.6.4" - no-case@^2.2.0: version "2.3.2" resolved "https://registry.yarnpkg.com/no-case/-/no-case-2.3.2.tgz#60b813396be39b3f1288a4c1ed5d1e7d28b464ac" dependencies: lower-case "^1.1.1" -nocache@^2.0.0: - version "2.0.0" - resolved "https://registry.yarnpkg.com/nocache/-/nocache-2.0.0.tgz#202b48021a0c4cbde2df80de15a17443c8b43980" - node-fetch@^1.3.3: version "1.7.3" resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-1.7.3.tgz#980f6f72d85211a5347c6b2bc18c5b84c3eb47ef" @@ -5045,12 +4911,6 @@ path-to-regexp@0.1.7: version "0.1.7" resolved "https://registry.yarnpkg.com/path-to-regexp/-/path-to-regexp-0.1.7.tgz#df604178005f522f15eb4490e7247a1bfaa67f8c" -path-to-regexp@^1.7.0: - version "1.7.0" - resolved "https://registry.yarnpkg.com/path-to-regexp/-/path-to-regexp-1.7.0.tgz#59fde0f435badacba103a84e9d3bc64e96b9937d" - dependencies: - isarray "0.0.1" - path-type@^1.0.0: version "1.1.0" resolved "https://registry.yarnpkg.com/path-type/-/path-type-1.1.0.tgz#59c44f7ee491da704da415da5a4070ba4f8fe441" @@ -5174,18 +5034,10 @@ qs@6.5.1, qs@^6.4.0: version "6.5.1" resolved "https://registry.yarnpkg.com/qs/-/qs-6.5.1.tgz#349cdf6eef89ec45c12d7d5eb3fc0c870343a6d8" -qs@6.5.2: - version "6.5.2" - resolved "https://registry.yarnpkg.com/qs/-/qs-6.5.2.tgz#cb3ae806e8740444584ef154ce8ee98d403f3e36" - qs@~6.4.0: version "6.4.0" resolved "https://registry.yarnpkg.com/qs/-/qs-6.4.0.tgz#13e26d28ad6b0ffaa91312cd3bf708ed351e7233" -querystringify@^2.0.0: - version "2.0.0" - resolved "https://registry.yarnpkg.com/querystringify/-/querystringify-2.0.0.tgz#fa3ed6e68eb15159457c89b37bc6472833195755" - quick-temp@^0.1.2, quick-temp@^0.1.3, quick-temp@^0.1.5, quick-temp@^0.1.8: version "0.1.8" resolved "https://registry.yarnpkg.com/quick-temp/-/quick-temp-0.1.8.tgz#bab02a242ab8fb0dd758a3c9776b32f9a5d94408" @@ -5226,15 +5078,6 @@ raw-body@2.3.2: iconv-lite "0.4.19" unpipe "1.0.0" -raw-body@2.3.3: - version "2.3.3" - resolved "https://registry.yarnpkg.com/raw-body/-/raw-body-2.3.3.tgz#1b324ece6b5706e153855bc1148c65bb7f6ea0c3" - dependencies: - bytes "3.0.0" - http-errors "1.6.3" - iconv-lite "0.4.23" - unpipe "1.0.0" - raw-body@~1.1.0: version "1.1.7" resolved "https://registry.yarnpkg.com/raw-body/-/raw-body-1.1.7.tgz#1d027c2bfa116acc6623bca8f00016572a87d425" @@ -5443,7 +5286,7 @@ require-uncached@^1.0.3: caller-path "^0.1.0" resolve-from "^1.0.0" -requires-port@1.x.x, requires-port@^1.0.0: +requires-port@1.x.x: version "1.0.0" resolved "https://registry.yarnpkg.com/requires-port/-/requires-port-1.0.0.tgz#925d2601d39ac485e091cf0da5c6e694dc3dcaff" @@ -5519,10 +5362,6 @@ rimraf@~2.2.6: version "2.2.8" resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-2.2.8.tgz#e439be2aaee327321952730f99a8929e4fc50582" -route-recognizer@^0.3.3: - version "0.3.3" - resolved "https://registry.yarnpkg.com/route-recognizer/-/route-recognizer-0.3.3.tgz#1d365e27fa6995e091675f7dc940a8c00353bd29" - rsvp@^3.0.14, rsvp@^3.0.16, rsvp@^3.0.17, rsvp@^3.0.18, rsvp@^3.0.21, rsvp@^3.0.6, rsvp@^3.1.0, rsvp@^3.2.1, rsvp@^3.3.3, rsvp@^3.5.0: version "3.6.2" resolved "https://registry.yarnpkg.com/rsvp/-/rsvp-3.6.2.tgz#2e96491599a96cde1b515d5674a8f7a91452926a" @@ -5569,14 +5408,10 @@ safe-regex@^1.1.0: dependencies: ret "~0.1.10" -"safer-buffer@>= 2.1.2 < 3", safer-buffer@^2.1.0: +safer-buffer@^2.1.0: version "2.1.2" resolved "https://registry.yarnpkg.com/safer-buffer/-/safer-buffer-2.1.2.tgz#44fa161b0187b9549dd84bb91802f9bd8385cd6a" -samsam@1.3.0: - version "1.3.0" - resolved "https://registry.yarnpkg.com/samsam/-/samsam-1.3.0.tgz#8d1d9350e25622da30de3e44ba692b5221ab7c50" - sane@^2.2.0, sane@^2.4.1: version "2.5.0" resolved "https://registry.yarnpkg.com/sane/-/sane-2.5.0.tgz#6359cd676f5efd9988b264d8ce3b827dd6b27bec" @@ -5699,10 +5534,6 @@ slice-ansi@1.0.0: dependencies: is-fullwidth-code-point "^2.0.0" -slugify@^1.3.0: - version "1.3.0" - resolved "https://registry.yarnpkg.com/slugify/-/slugify-1.3.0.tgz#787919259d28c825fbcae6da2e01c77a109793f6" - snake-case@^2.1.0: version "2.1.0" resolved "https://registry.yarnpkg.com/snake-case/-/snake-case-2.1.0.tgz#41bdb1b73f30ec66a04d4e2cad1b76387d4d6d9f" @@ -6130,10 +5961,6 @@ testem@^2.0.0: tap-parser "^5.1.0" xmldom "^0.1.19" -text-encoding@^0.6.4: - version "0.6.4" - resolved "https://registry.yarnpkg.com/text-encoding/-/text-encoding-0.6.4.tgz#e399a982257a276dae428bb92845cb71bdc26d19" - text-table@~0.2.0: version "0.2.0" resolved "https://registry.yarnpkg.com/text-table/-/text-table-0.2.0.tgz#7f5ee823ae805207c00af2df4a84ec3fcfa570b4" @@ -6343,13 +6170,6 @@ urix@^0.1.0: version "0.1.0" resolved "https://registry.yarnpkg.com/urix/-/urix-0.1.0.tgz#da937f7a62e21fec1fd18d49b35c2935067a6c72" -url-parse@^1.4.1: - version "1.4.1" - resolved "https://registry.yarnpkg.com/url-parse/-/url-parse-1.4.1.tgz#4dec9dad3dc8585f862fed461d2e19bbf623df30" - dependencies: - querystringify "^2.0.0" - requires-port "^1.0.0" - use@^3.1.0: version "3.1.0" resolved "https://registry.yarnpkg.com/use/-/use-3.1.0.tgz#14716bf03fdfefd03040aef58d8b4b85f3a7c544"