@@ -356,18 +356,33 @@ static void append_http_status_line(smart_str *buffer, int protocol_version, int
356
356
smart_str_appendl_ex (buffer , "\r\n" , 2 , persistent );
357
357
} /* }}} */
358
358
359
- static void append_essential_headers (smart_str * buffer , php_cli_server_client * client , bool persistent ) /* {{{ */
359
+ static void append_essential_headers (smart_str * buffer , php_cli_server_client * client , bool persistent , sapi_headers_struct * sapi_headers ) /* {{{ */
360
360
{
361
361
zval * val ;
362
362
struct timeval tv = {0 };
363
+ bool append_date_header = true;
364
+
365
+ if (sapi_headers != NULL ) {
366
+ zend_llist_position pos ;
367
+ sapi_header_struct * h = (sapi_header_struct * )zend_llist_get_first_ex (& sapi_headers -> headers , & pos );
368
+ while (h ) {
369
+ if (h -> header_len > strlen ("Date:" )) {
370
+ if (strncasecmp (h -> header , "Date:" , strlen ("Date:" )) == 0 ) {
371
+ append_date_header = false;
372
+ break ;
373
+ }
374
+ }
375
+ h = (sapi_header_struct * )zend_llist_get_next_ex (& sapi_headers -> headers , & pos );
376
+ }
377
+ }
363
378
364
379
if (NULL != (val = zend_hash_find (& client -> request .headers , ZSTR_KNOWN (ZEND_STR_HOST )))) {
365
380
smart_str_appends_ex (buffer , "Host: " , persistent );
366
381
smart_str_append_ex (buffer , Z_STR_P (val ), persistent );
367
382
smart_str_appends_ex (buffer , "\r\n" , persistent );
368
383
}
369
384
370
- if (!gettimeofday (& tv , NULL )) {
385
+ if (append_date_header && !gettimeofday (& tv , NULL )) {
371
386
zend_string * dt = php_format_date ("D, d M Y H:i:s" , sizeof ("D, d M Y H:i:s" ) - 1 , tv .tv_sec , 0 );
372
387
smart_str_appends_ex (buffer , "Date: " , persistent );
373
388
smart_str_append_ex (buffer , dt , persistent );
@@ -551,7 +566,7 @@ static int sapi_cli_server_send_headers(sapi_headers_struct *sapi_headers) /* {{
551
566
append_http_status_line (& buffer , client -> request .protocol_version , SG (sapi_headers ).http_response_code , 0 );
552
567
}
553
568
554
- append_essential_headers (& buffer , client , 0 );
569
+ append_essential_headers (& buffer , client , 0 , sapi_headers );
555
570
556
571
h = (sapi_header_struct * )zend_llist_get_first_ex (& sapi_headers -> headers , & pos );
557
572
while (h ) {
@@ -2049,7 +2064,7 @@ static zend_result php_cli_server_send_error_page(php_cli_server *server, php_cl
2049
2064
/* out of memory */
2050
2065
goto fail ;
2051
2066
}
2052
- append_essential_headers (& buffer , client , 1 );
2067
+ append_essential_headers (& buffer , client , 1 , NULL );
2053
2068
smart_str_appends_ex (& buffer , "Content-Type: text/html; charset=UTF-8\r\n" , 1 );
2054
2069
smart_str_appends_ex (& buffer , "Content-Length: " , 1 );
2055
2070
smart_str_append_unsigned_ex (& buffer , php_cli_server_buffer_size (& client -> content_sender .buffer ), 1 );
@@ -2165,7 +2180,7 @@ static zend_result php_cli_server_begin_send_static(php_cli_server *server, php_
2165
2180
php_cli_server_log_response (client , 500 , NULL );
2166
2181
return FAILURE ;
2167
2182
}
2168
- append_essential_headers (& buffer , client , 1 );
2183
+ append_essential_headers (& buffer , client , 1 , NULL );
2169
2184
if (mime_type ) {
2170
2185
smart_str_appendl_ex (& buffer , "Content-Type: " , sizeof ("Content-Type: " ) - 1 , 1 );
2171
2186
smart_str_appends_ex (& buffer , mime_type , 1 );
0 commit comments