-
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
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
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?
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.
No it's not because it doesn't get the "Set-Cookie"
len - it just know the total prefix len so it cannot check for it.
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.
And it also doesn't check the separator because that's done only for SAPI_HEADER_DELETE
variant.
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.
Ah, I see what you mean. I think I can restore this optimization.
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.
Suggestion from Jakub.
0ef7bff
to
251542b
Compare
I don't think this needs to be special cased with the parameter.
size_t header_len = len; | ||
const char *colon = strchr(name, ':'); | ||
if (colon) { | ||
header_len = (size_t)(colon - name); | ||
} |
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 beats the whole purpose of doing that header->header[header_len] == ':'
which is pretty much pointless now.
I think there could be much easier way to pass the header_len
. When you look to sapi_header_line
, there is a response_code
field so you could use anonymous union so it looks like:
typedef struct {
const char *line; /* If you allocated this, you need to free it yourself */
size_t line_len;
union {
zend_long response_code; /* long due to zend_parse_parameters compatibility */
size_t header_len;
};
} sapi_header_line;
Then you could pass it from the session.
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.)