Skip to content

Commit 999af5f

Browse files
committed
Preserve 301/302 method and support 307/308 (#3106, #5115).
1 parent acd2424 commit 999af5f

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

src.ts/utils/fetch.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ export class FetchRequest implements Iterable<[ key: string, value: string ]> {
539539
const resp = await this.getUrlFunc(req, checkSignal(_request.#signal));
540540
let response = new FetchResponse(resp.statusCode, resp.statusMessage, resp.headers, resp.body, _request);
541541

542-
if (response.statusCode === 301 || response.statusCode === 302) {
542+
if ([301, 302, 307, 308].indexOf(response.statusCode) >= 0) {
543543

544544
// Redirect
545545
try {
@@ -615,16 +615,15 @@ export class FetchRequest implements Iterable<[ key: string, value: string ]> {
615615
const target = location.split(":")[0].toLowerCase();
616616

617617
// Don't allow redirecting:
618-
// - non-GET requests
619618
// - downgrading the security (e.g. https => http)
620619
// - to non-HTTP (or non-HTTPS) protocols [this could be relaxed?]
621-
assert(this.method === "GET" && (current !== "https" || target !== "http") && location.match(/^https?:/), `unsupported redirect`, "UNSUPPORTED_OPERATION", {
620+
assert((current !== "https" || target !== "http") && location.match(/^https?:/), `unsupported redirect`, "UNSUPPORTED_OPERATION", {
622621
operation: `redirect(${ this.method } ${ JSON.stringify(this.url) } => ${ JSON.stringify(location) })`
623622
});
624623

625624
// Create a copy of this request, with a new URL
626625
const req = new FetchRequest(location);
627-
req.method = "GET";
626+
req.method = this.method;
628627
req.allowGzip = this.allowGzip;
629628
req.timeout = this.timeout;
630629
req.#headers = Object.assign({ }, this.#headers);

0 commit comments

Comments
 (0)