Skip to content

Add SAPI_HEADER_DELETE_PREFIX, make ext/session use it #18678

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

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

NattyNarwhal
Copy link
Member

@NattyNarwhal NattyNarwhal commented May 27, 2025

Refactoring this as part of triaging GH-18601 - I don't think it'll fix the issue, but it's a good idea to clean anyways. ext/session had its own copy of the remove header code, because the SAPI header op mandated it was just a name, and would remove all headers for that name. ext/session couldn't rely on this because it only wanted to remove a specific cookie, not all of them.

To simplify this, add a version of SAPI_HEADER_DELETE that is more flexible and allows for passing a prefix to check for, not just a name. This should work for removing a specific cookie from the headers. (Also fixes some whitespace too.)

Copy link
Member

@Girgias Girgias left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Happy with the ext/session changes, makes sense to delegate this to the SAPI layer.

@NattyNarwhal NattyNarwhal changed the title Add SAPI_HEADER_REMOVE_PREFIX, make ext/session use it Add SAPI_HEADER_DELETE_PREFIX, make ext/session use it May 28, 2025
Copy link
Member

@bukka bukka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that this logic should be in SAPI.c but it might be better to have more specialized variants (even specifically for Set-Cookie wrapped in SAPI functions.

I would prefer not use header_line but just wrapping functions instead though.

Copy link
Member

@bukka bukka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, all looks good to me!

The session ext currently munges into the linked list of headers
itself, because the delete header API is given the key for headers to
delete. The session ext wants to use a prefix past the colon separator,
for i.e. "Set-Cookie: PHPSESSID=", to eliminate only the specific cookie
rather than all cookies.

This changes the SAPI code to add a new header op to take a prefix
instead. Call sites are yet unchanged. Also fix some whitespace.
Use the modern SAPI header ops API, including the remove prefix op we
just added.
The purpose of this is clear, and after refactoring, the special case is
no longer there, so it has no value.
I don't think this needs to be special cased with the parameter.
It may be better to use spaces in here instead.
@NattyNarwhal
Copy link
Member Author

Made that cosmetic tweak and rebased.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants