Skip to content

Commit 8cd5992

Browse files
committed
Move setting header length to caller
Suggestion from Jakub.
1 parent 2c0fb89 commit 8cd5992

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

ext/session/session.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1344,6 +1344,7 @@ static void php_session_remove_cookie(void) {
13441344

13451345
header_line.line = session_cookie;
13461346
header_line.line_len = strlen(session_cookie);
1347+
header_line.header_len = sizeof("Set-Cookie") - 1;
13471348
sapi_header_op(SAPI_HEADER_DELETE_PREFIX, &header_line);
13481349

13491350
efree(session_cookie);

main/SAPI.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -597,18 +597,12 @@ static void sapi_update_response_code(int ncode)
597597
* since zend_llist_del_element only removes one matched item once,
598598
* we should remove them manually
599599
*/
600-
static void sapi_remove_header(zend_llist *l, char *name, size_t len)
600+
static void sapi_remove_header(zend_llist *l, char *name, size_t len, size_t header_len)
601601
{
602602
sapi_header_struct *header;
603603
zend_llist_element *next;
604604
zend_llist_element *current=l->head;
605605

606-
size_t header_len = len;
607-
const char *colon = strchr(name, ':');
608-
if (colon) {
609-
header_len = (size_t)(colon - name);
610-
}
611-
612606
while (current) {
613607
header = (sapi_header_struct *)(current->data);
614608
next = current->next;
@@ -661,7 +655,7 @@ static void sapi_header_add_op(sapi_header_op_enum op, sapi_header_struct *sapi_
661655
char sav = *colon_offset;
662656

663657
*colon_offset = 0;
664-
sapi_remove_header(&SG(sapi_headers).headers, sapi_header->header, strlen(sapi_header->header));
658+
sapi_remove_header(&SG(sapi_headers).headers, sapi_header->header, strlen(sapi_header->header), 0);
665659
*colon_offset = sav;
666660
}
667661
}
@@ -676,7 +670,7 @@ SAPI_API int sapi_header_op(sapi_header_op_enum op, void *arg)
676670
sapi_header_struct sapi_header;
677671
char *colon_offset;
678672
char *header_line;
679-
size_t header_line_len;
673+
size_t header_line_len, header_len;
680674
int http_response_code;
681675

682676
if (SG(headers_sent) && !SG(request_info).no_headers) {
@@ -708,7 +702,13 @@ SAPI_API int sapi_header_op(sapi_header_op_enum op, void *arg)
708702
}
709703
header_line = estrndup(p->line, p->line_len);
710704
header_line_len = p->line_len;
711-
http_response_code = p->response_code;
705+
if (op == SAPI_HEADER_DELETE_PREFIX) {
706+
header_len = p->header_len;
707+
http_response_code = 0;
708+
} else {
709+
header_len = 0;
710+
http_response_code = p->response_code;
711+
}
712712
break;
713713
}
714714

@@ -742,7 +742,7 @@ SAPI_API int sapi_header_op(sapi_header_op_enum op, void *arg)
742742
sapi_header.header_len = header_line_len;
743743
sapi_module.header_handler(&sapi_header, op, &SG(sapi_headers));
744744
}
745-
sapi_remove_header(&SG(sapi_headers).headers, header_line, header_line_len);
745+
sapi_remove_header(&SG(sapi_headers).headers, header_line, header_line_len, header_len);
746746
efree(header_line);
747747
return SUCCESS;
748748
} else {

main/SAPI.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,10 @@ END_EXTERN_C()
185185
typedef struct {
186186
const char *line; /* If you allocated this, you need to free it yourself */
187187
size_t line_len;
188-
zend_long response_code; /* long due to zend_parse_parameters compatibility */
188+
union {
189+
zend_long response_code; /* long due to zend_parse_parameters compatibility */
190+
size_t header_len; /* the "Key" in "Key: Value", for optimization */
191+
};
189192
} sapi_header_line;
190193

191194
typedef enum { /* Parameter: */

0 commit comments

Comments
 (0)