Skip to content

Commit

Permalink
Merge pull request #15 from maccyber/reset_body_and_method_when_redir
Browse files Browse the repository at this point in the history
Resets body, method and content-length when redirected
  • Loading branch information
jd1378 authored Dec 12, 2022
2 parents 96f2428 + 6022788 commit 7f8a1ef
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions fetch_wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,16 @@ export function wrapFetch(options?: WrapFetchOptions): typeof fetch {

// Do not forward sensitive headers to third-party domains.
if (!isDomainOrSubdomain(originalRequestUrl, redirectUrl)) {
for (
const name of ["authorization", "www-authenticate"] // cookie headers are handled differently
) {
for (const name of ["authorization", "www-authenticate"]) { // cookie headers are handled differently
filteredHeaders.delete(name);
}
}

if (interceptedInit.method === "POST") {
filteredHeaders.delete("content-length");
interceptedInit.method = "GET";
interceptedInit.body = undefined;
}
interceptedInit.headers = filteredHeaders;

return await wrappedFetch(redirectUrl, interceptedInit as RequestInit);
Expand Down

0 comments on commit 7f8a1ef

Please sign in to comment.