-
-
Notifications
You must be signed in to change notification settings - Fork 28
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
Adds "remove cookie" function to request module #57
Adds "remove cookie" function to request module #57
Conversation
I think this would be confusing in that people would expect it to remove the cookie from the session, but it does not. What's your use case here? |
That's true but isn't that already how My specific use case is: In doing this I need to inject a session_cookie (containing the session id) in the request if that cookie does not already exist. (This cookie will then also be added to the response after the handler has ran). I do this using I think in general it would be most useful for replacing cookies in some way so maybe it's more of a utility function than something that should be in the main library, what do you think? |
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.
OK, you've convinced me :)
Could you document that this does not remove it from the client please.
src/gleam/http/request.gleam
Outdated
let new_cookies_string = | ||
string.split(cookies_string, ";") | ||
|> list.map(string.trim) | ||
|> list.filter(fn(str) { string.starts_with(str, name) |> bool.negate }) |
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.
In case you didn't know, you can use !
rather than bool.negate
, it's a bit shorter.
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.
I did not, nice! Updated in next commit :)
|> request.get_header("cookie") | ||
|> should.be_ok | ||
|> should.equal("FIRST_COOKIE=first; THIRD_COOKIE=third") | ||
} |
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.
Could we have a test to check that if you try and remove "SECOND" it won't remove "SECOND_COOKIE" please 🙏
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.
Oh, good catch that was a bug. I had to rework the function a tiny bit to fix it. Update pushed.
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.
Thank you
src/gleam/http/request.gleam
Outdated
@@ -1,5 +1,6 @@ | |||
import gleam/http.{type Header, type Method, type Scheme, Get} | |||
import gleam/http/cookie | |||
import gleam/io |
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.
I think this was for debugging?
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.
Yep, It slipped through 😅
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.
Beautiful! Would you mind updating the changelog?
63e7161
to
d471e09
Compare
Yes, absolutely, is this correct? |
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.
Thank you
This pull request adds a remove_cookie function to the request.
This is useful if you want to for example override a cookie sent from the browser. Since set_cookie appends cookies. Existing cookies in the header would therefore take presidence over the newly set cookies. This might be desirable but the remove_cookie function is a solution in the case that it's not.