-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handle set-cookie from a redirect response fixes #13 #14
Handle set-cookie from a redirect response fixes #13 #14
Conversation
TODO: Add maxRedirect, redirectCount, test better, and maybe extract some functions
fetch_wrapper.ts
Outdated
@@ -37,13 +46,53 @@ export function wrapFetch(options?: WrapFetchOptions): typeof fetch { | |||
} | |||
interceptedInit.headers.set("cookie", cookieString); | |||
|
|||
const response = await fetch(input, interceptedInit); | |||
const response = await fetch(input, { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we not use spread operator for this and simply set redirect
on interceptedInit
directly ?
the reason is spread has a cost, and I prefer to not use it when It's not needed
even if we want to clone user's init
, in this case which we should have, let's do it once and when we assign the interceptedInit
also probably change interceptedInit
type to WrappedFetchRequestInit
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. Tried to refactor it, but it still doesn't feel right. Must be better ways to solve it.
I hope someone else can push this over the line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for the effort
I agree, it does not feel right.
I'll work on it when I have some time
fetch_wrapper.ts
Outdated
); | ||
} | ||
|
||
init = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here about the spread
also shouldn't it be changing interceptedInit
?
also maybe do a deepStrictEqual assert on user's init so we make sure to not accidentally mutate their init from now on ? |
I have committed some changes also I think the naming was good the way it was, so I renamed them back, sorry the only thing remaining from tasks is |
I'm ready to merge, the only remaining task which I did not understand was "Handle deletion of cookie headers" |
Awesome. I updated the task to "Do not forward sensitive headers (i.e. I think I can create a test for it later tonight |
since I still did not understand, I appreciate the incoming tests :D edit: my bad, |
Implementation of this functionality in fetch-cookie: https://github.com/valeriangalliat/fetch-cookie/blob/master/src/index.ts#L161-L166 |
from what I understood, we were already hitting the check here and resetting it always here so I think adding a test should make it clear if It's as I'm thinking or we need to change anything edit: sorry, I keep missing the point |
I would be happy if you took a look at the test and the code guarding what it should the cookie header part is handled differently by resetting them for every request if everything is fine, tell me so I can merge |
to conform to rfc 6265
I've also noticed I should have used |
Kudos, SonarCloud Quality Gate passed!
|
Nice, looks good to me |
thanks a lot for this ! |
TODO:
redirect: "manual"
is sent through fetch optionsredirect: "error"
is sent through fetch optionsresponse.redirected
when redirected