Skip to content

Commit f33c7b3

Browse files
seeschlossweltling
authored andcommitted
Added mandatory Date: header to built-in webserver
1 parent 56b2a49 commit f33c7b3

27 files changed

+44
-0
lines changed

sapi/cli/php_cli_server.c

+8
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@
9696
#include "ext/standard/html.h"
9797
#include "ext/standard/url.h" /* for php_raw_url_decode() */
9898
#include "ext/standard/php_string.h" /* for php_dirname() */
99+
#include "ext/date/php_date.h" /* for php_format_date() */
99100
#include "php_network.h"
100101

101102
#include "php_http_parser.h"
@@ -348,6 +349,13 @@ static void append_essential_headers(smart_str* buffer, php_cli_server_client *c
348349
smart_str_appendl_ex(buffer, "\r\n", 2, persistent);
349350
}
350351
}
352+
time_t t;
353+
time(&t);
354+
zend_string *dt = php_format_date("r", 1, t, 1);
355+
smart_str_appendl_ex(buffer, "Date: ", 6, persistent);
356+
smart_str_appends_ex(buffer, dt->val, persistent);
357+
smart_str_appendl_ex(buffer, "\r\n", 2, persistent);
358+
351359
smart_str_appendl_ex(buffer, "Connection: close\r\n", sizeof("Connection: close\r\n") - 1, persistent);
352360
} /* }}} */
353361

sapi/cli/tests/bug43177.phpt

+4
Original file line numberDiff line numberDiff line change
@@ -61,25 +61,29 @@ HEADER
6161
--EXPECTF--
6262
HTTP/1.1 200 OK
6363
Host: localhost
64+
Date: %s
6465
Connection: close
6566
X-Powered-By: %s
6667
Content-type: text/html; charset=UTF-8
6768

6869
OK
6970
HTTP/1.0 500 Internal Server Error
7071
Host: localhost
72+
Date: %s
7173
Connection: close
7274
X-Powered-By: %s
7375
Content-type: text/html; charset=UTF-8
7476

7577
HTTP/1.0 500 Internal Server Error
7678
Host: localhost
79+
Date: %s
7780
Connection: close
7881
X-Powered-By: %s
7982
Content-type: text/html; charset=UTF-8
8083

8184
HTTP/1.0 500 Internal Server Error
8285
Host: localhost
86+
Date: %s
8387
Connection: close
8488
X-Powered-By: %s
8589
Content-type: text/html; charset=UTF-8

sapi/cli/tests/bug65066_100.phpt

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ HEADER
3434
--EXPECTF--
3535
HTTP/1.1 100 Continue
3636
Host: %s
37+
Date: %s
3738
Connection: close
3839
X-Powered-By: PHP/%s
3940
Content-type: text/html; charset=UTF-8

sapi/cli/tests/bug65066_422.phpt

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ HEADER
3434
--EXPECTF--
3535
HTTP/1.1 422 Unknown Status Code
3636
Host: %s
37+
Date: %s
3738
Connection: close
3839
X-Powered-By: PHP/%s
3940
Content-type: text/html; charset=UTF-8

sapi/cli/tests/bug65066_511.phpt

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ HEADER
3434
--EXPECTF--
3535
HTTP/1.1 511 Network Authentication Required
3636
Host: %s
37+
Date: %s
3738
Connection: close
3839
X-Powered-By: PHP/%s
3940
Content-type: text/html; charset=UTF-8

sapi/cli/tests/bug65633.phpt

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ fclose($fp);
3737
?>
3838
--EXPECTF--
3939
HTTP/1.1 200 OK
40+
Date: %s
4041
Connection: close
4142
X-Powered-By: %s
4243
Content-type: text/html; charset=UTF-8

sapi/cli/tests/bug66606_2.phpt

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ fclose($fp);
3838
--EXPECTF--
3939
HTTP/1.1 200 OK
4040
Host: %s
41+
Date: %s
4142
Connection: close
4243
X-Powered-By: PHP/%s
4344
Content-type: text/html; charset=UTF-8

sapi/cli/tests/bug66830.phpt

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ fclose($fp);
3737
--EXPECTF--
3838
HTTP/1.1 200 OK
3939
Host: %s
40+
Date: %s
4041
Connection: close
4142
X-Powered-By: %s
4243
Content-type: text/html; charset=UTF-8

sapi/cli/tests/bug67429.phpt

+2
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,13 @@ HEADER
3838
?>
3939
--EXPECTF--
4040
HTTP/1.1 308 Permanent Redirect
41+
Date: %s
4142
Connection: close
4243
X-Powered-By: %s
4344
Content-type: text/html; charset=UTF-8
4445

4546
HTTP/1.1 426 Upgrade Required
47+
Date: %s
4648
Connection: close
4749
X-Powered-By: %s
4850
Content-type: text/html; charset=UTF-8

sapi/cli/tests/bug68745.phpt

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ fclose($fp);
2727
?>
2828
--EXPECTF--
2929
HTTP/1.1 200 OK
30+
Date: %s
3031
Connection: close
3132
X-Powered-By: %s
3233
Content-type: text/html; charset=UTF-8

sapi/cli/tests/bug71005.phpt

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ HEADER
3939
--EXPECTF--
4040
HTTP/1.1 200 OK
4141
Host: %s
42+
Date: %s
4243
Connection: close
4344
X-Powered-By: PHP/%s
4445
Content-type: text/html; charset=UTF-8

sapi/cli/tests/php_cli_server_004.phpt

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ HEADER
3838
--EXPECTF--
3939
HTTP/1.1 200 OK
4040
Host: %s
41+
Date: %s
4142
Connection: close
4243
X-Powered-By: PHP/%s
4344
Content-type: text/html; charset=UTF-8

sapi/cli/tests/php_cli_server_005.phpt

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ HEADER
5050
--EXPECTF--
5151
HTTP/1.1 200 OK
5252
Host: %s
53+
Date: %s
5354
Connection: close
5455
X-Powered-By: PHP/%s
5556
Content-type: text/html; charset=UTF-8

sapi/cli/tests/php_cli_server_006.phpt

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ HEADER
3434
--EXPECTF--
3535
HTTP/1.1 200 OK
3636
Host: %s
37+
Date: %s
3738
Connection: close
3839
X-Powered-By: PHP/%s
3940
Content-type: text/html; charset=UTF-8

sapi/cli/tests/php_cli_server_007.phpt

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ HEADER
3434
--EXPECTF--
3535
HTTP/1.1 401 Unauthorized
3636
Host: %s
37+
Date: %s
3738
Connection: close
3839
X-Powered-By: PHP/%s
3940
WWW-Authenticate: Digest realm="foo",qop="auth",nonce="XXXXX",opaque="acbd18db4cc2f85cedef654fccc4a4d8"

sapi/cli/tests/php_cli_server_008.phpt

+2
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,15 @@ fclose($fp);
5454
--EXPECTF--
5555
HTTP/1.1 200 OK
5656
Host: %s
57+
Date: %s
5758
Connection: close
5859
X-Powered-By: PHP/%s
5960
Content-type: text/html; charset=UTF-8
6061

6162
string(8) "HTTP/1.1"
6263
HTTP/1.0 200 OK
6364
Host: %s
65+
Date: %s
6466
Connection: close
6567
X-Powered-By: PHP/%s
6668
Content-type: text/html; charset=UTF-8

sapi/cli/tests/php_cli_server_009.phpt

+2
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,15 @@ fclose($fp);
7878
--EXPECTF--
7979
HTTP/1.1 200 OK
8080
Host: %s
81+
Date: %s
8182
Connection: close
8283
X-Powered-By: PHP/%s
8384
Content-type: text/html; charset=UTF-8
8485

8586
string(8) "/foo/bar"
8687
HTTP/1.0 200 OK
8788
Host: %s
89+
Date: %s
8890
Connection: close
8991
X-Powered-By: PHP/%s
9092
Content-type: text/html; charset=UTF-8

sapi/cli/tests/php_cli_server_010.phpt

+2
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ fclose($fp);
5555
--EXPECTF--
5656
HTTP/1.1 200 OK
5757
Host: %s
58+
Date: %s
5859
Connection: close
5960
X-Powered-By: PHP/%s
6061
Content-type: text/html; charset=UTF-8
@@ -65,6 +66,7 @@ string(8) "/foo/bar"
6566
string(7) "foo=bar"
6667
HTTP/1.0 200 OK
6768
Host: %s
69+
Date: %s
6870
Connection: close
6971
X-Powered-By: PHP/%s
7072
Content-type: text/html; charset=UTF-8

sapi/cli/tests/php_cli_server_012.phpt

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ fclose($fp);
4040
--EXPECTF--
4141
HTTP/1.1 200 OK
4242
Host: %s
43+
Date: %s
4344
Connection: close
4445
X-Powered-By: PHP/%s
4546
Content-type: text/html; charset=UTF-8

sapi/cli/tests/php_cli_server_013.phpt

+3
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ fclose($fp);
8383

8484
HTTP/1.1 404 Not Found
8585
Host: %s
86+
Date: %s
8687
Connection: close
8788
Content-Type: text/html; charset=UTF-8
8889
Content-Length: %d
@@ -91,6 +92,7 @@ Content-Length: %d
9192
</head><body><h1>Not Found</h1><p>The requested resource <code class="url">/</code> was not found on this server.</p></body></html>
9293
HTTP/1.1 404 Not Found
9394
Host: %s
95+
Date: %s
9496
Connection: close
9597
Content-Type: text/html; charset=UTF-8
9698
Content-Length: %d
@@ -99,6 +101,7 @@ Content-Length: %d
99101
</head><body><h1>Not Found</h1><p>The requested resource <code class="url">/main/style.css</code> was not found on this server.</p></body></html>
100102
HTTP/1.1 404 Not Found
101103
Host: %s
104+
Date: %s
102105
Connection: close
103106
Content-Type: text/html; charset=UTF-8
104107
Content-Length: %d

sapi/cli/tests/php_cli_server_014.phpt

+2
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,15 @@ fclose($fp);
6565

6666
HTTP/1.1 200 OK
6767
Host: %s
68+
Date: %s
6869
Connection: close
6970
X-Powered-By: %s
7071
Content-type: %s
7172

7273
done
7374
HTTP/1.1 404 Not Found
7475
Host: %s
76+
Date: %s
7577
Connection: close
7678
Content-Type: %s
7779
Content-Length: %d

sapi/cli/tests/php_cli_server_015.phpt

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ fclose($fp);
4141
--EXPECTF--
4242
HTTP/1.1 200 OK
4343
Host: %s
44+
Date: %s
4445
Connection: close
4546
X-Powered-By: PHP/%s
4647
Content-type: text/html; charset=UTF-8

sapi/cli/tests/php_cli_server_017.phpt

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ fclose($fp);
3737
--EXPECTF--
3838
HTTP/1.1 200 OK
3939
Host: %s
40+
Date: %s
4041
Connection: close
4142
X-Powered-By: %s
4243
Content-type: text/html; charset=UTF-8

sapi/cli/tests/php_cli_server_018.phpt

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ fclose($fp);
3737
--EXPECTF--
3838
HTTP/1.1 200 OK
3939
Host: %s
40+
Date: %s
4041
Connection: close
4142
X-Powered-By: %s
4243
Content-type: text/html; charset=UTF-8

sapi/cli/tests/php_cli_server_019.phpt

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ fclose($fp);
4141
--EXPECTF--
4242
HTTP/1.1 200 OK
4343
Host: %s
44+
Date: %s
4445
Connection: close
4546
X-Powered-By: %s
4647
Bar-Foo: Foo

sapi/cli/tests/php_cli_server_020.phpt

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ HEADER
3333
--EXPECTF--
3434
HTTP/1.1 200 OK
3535
Host: %s
36+
Date: %s
3637
Connection: close
3738
X-Powered-By: PHP/%s
3839
Content-type: text/html; charset=UTF-8

sapi/cli/tests/upload_2G.phpt

+1
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ Test
8181

8282
HTTP/1.1 200 OK
8383
Host: %s
84+
Date: %s
8485
Connection: close
8586
X-Powered-By: PHP/%s
8687
Content-type: text/html; charset=UTF-8

0 commit comments

Comments
 (0)