-
Notifications
You must be signed in to change notification settings - Fork 7.9k
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
base: master
Are you sure you want to change the base?
Conversation
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.
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.
Happy with the ext/session changes, makes sense to delegate this to the SAPI layer.
SAPI_HEADER_REMOVE_PREFIX
, make ext/session use itSAPI_HEADER_DELETE_PREFIX
, make ext/session use it
The purpose of this is clear, and after refactoring, the special case is no longer there, so it has no value.
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 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.
while (current) { | ||
header = (sapi_header_struct *)(current->data); | ||
next = current->next; | ||
if (header->header_len > len && header->header[len] == ':' |
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.
Think this is meant to be a micro optimization that it checks that the header is size of Set-Cookie header which might skip some strncmp calls...
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 optimization should still be preserved in sapi_remove_header
though?
header_line.line = ZSTR_VAL(ncookie.s); | ||
header_line.line_len = ZSTR_LEN(ncookie.s); | ||
sapi_header_op(SAPI_HEADER_ADD, &header_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.
I don't think there's much point in this and previous version is probably better for outside SAPI usage.
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.
The reason why I did this was because sapi_add_header_ex
was marked as deprecated in the header and to use sapi_header_op
instead.
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.)