-
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1335,51 +1335,23 @@ static int php_session_cache_limiter(void) | |
* Cookie Management * | ||
********************* */ | ||
|
||
/* | ||
* Remove already sent session ID cookie. | ||
* It must be directly removed from SG(sapi_header) because sapi_add_header_ex() | ||
* removes all of matching cookie. i.e. It deletes all of Set-Cookie headers. | ||
*/ | ||
static void php_session_remove_cookie(void) { | ||
sapi_header_struct *header; | ||
zend_llist *l = &SG(sapi_headers).headers; | ||
zend_llist_element *next; | ||
zend_llist_element *current; | ||
char *session_cookie; | ||
size_t session_cookie_len; | ||
size_t len = sizeof("Set-Cookie")-1; | ||
sapi_header_line header_line = {0}; | ||
|
||
ZEND_ASSERT(strpbrk(PS(session_name), SESSION_FORBIDDEN_CHARS) == NULL); | ||
spprintf(&session_cookie, 0, "Set-Cookie: %s=", PS(session_name)); | ||
|
||
session_cookie_len = strlen(session_cookie); | ||
current = l->head; | ||
while (current) { | ||
header = (sapi_header_struct *)(current->data); | ||
next = current->next; | ||
if (header->header_len > len && header->header[len] == ':' | ||
&& !strncmp(header->header, session_cookie, session_cookie_len)) { | ||
if (current->prev) { | ||
current->prev->next = next; | ||
} else { | ||
l->head = next; | ||
} | ||
if (next) { | ||
next->prev = current->prev; | ||
} else { | ||
l->tail = current->prev; | ||
} | ||
sapi_free_header(header); | ||
efree(current); | ||
--l->count; | ||
} | ||
current = next; | ||
} | ||
header_line.line = session_cookie; | ||
header_line.line_len = strlen(session_cookie); | ||
sapi_header_op(SAPI_HEADER_DELETE_PREFIX, &header_line); | ||
|
||
efree(session_cookie); | ||
} | ||
|
||
static zend_result php_session_send_cookie(void) | ||
{ | ||
sapi_header_line header_line = {0}; | ||
smart_str ncookie = {0}; | ||
zend_string *date_fmt = NULL; | ||
zend_string *e_id; | ||
|
@@ -1445,9 +1417,9 @@ static zend_result php_session_send_cookie(void) | |
smart_str_0(&ncookie); | ||
|
||
php_session_remove_cookie(); /* remove already sent session ID cookie */ | ||
/* 'replace' must be 0 here, else a previous Set-Cookie | ||
header, probably sent with setcookie() will be replaced! */ | ||
sapi_add_header_ex(estrndup(ZSTR_VAL(ncookie.s), ZSTR_LEN(ncookie.s)), ZSTR_LEN(ncookie.s), 0, 0); | ||
header_line.line = ZSTR_VAL(ncookie.s); | ||
header_line.line_len = ZSTR_LEN(ncookie.s); | ||
sapi_header_op(SAPI_HEADER_ADD, &header_line); | ||
Comment on lines
+1420
to
+1422
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. The reason why I did this was because |
||
smart_str_free(&ncookie); | ||
|
||
return SUCCESS; | ||
|
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?