MCPcopy Create free account
hub / github.com/nodejs/node / responseLocationURL

Function responseLocationURL

deps/undici/src/lib/web/fetch/util.js:25–55  ·  view source on GitHub ↗
(response, requestFragment)

Source from the content-addressed store, hash-verified

23
24// https://fetch.spec.whatwg.org/#concept-response-location-url
25function responseLocationURL (response, requestFragment) {
26 // 1. If response’s status is not a redirect status, then return null.
27 if (!redirectStatusSet.has(response.status)) {
28 return null
29 }
30
31 // 2. Let location be the result of extracting header list values given
32 // `Location` and response’s header list.
33 let location = response.headersList.get('location', true)
34
35 // 3. If location is a header value, then set location to the result of
36 // parsing location with response’s URL.
37 if (location !== null && isValidHeaderValue(location)) {
38 if (!isValidEncodedURL(location)) {
39 // Some websites respond location header in UTF-8 form without encoding them as ASCII
40 // and major browsers redirect them to correctly UTF-8 encoded addresses.
41 // Here, we handle that behavior in the same way.
42 location = normalizeBinaryStringToUtf8(location)
43 }
44 location = new URL(location, responseURL(response))
45 }
46
47 // 4. If location is a URL whose fragment is null, then set location’s
48 // fragment to requestFragment.
49 if (location && !location.hash) {
50 location.hash = requestFragment
51 }
52
53 // 5. Return location.
54 return location
55}
56
57/**
58 * @see https://www.rfc-editor.org/rfc/rfc1738#section-2.2

Callers 1

httpRedirectFetchFunction · 0.70

Calls 6

isValidHeaderValueFunction · 0.70
isValidEncodedURLFunction · 0.70
responseURLFunction · 0.70
hasMethod · 0.65
getMethod · 0.65

Tested by

no test coverage detected