Skip to content

Commit 1e60d0c

Browse files
committed
Implemented FR #61977 (Need CLI web-server support for files with .htm & svg extensions)
1 parent 7b2ab56 commit 1e60d0c

File tree

3 files changed

+166
-5
lines changed

3 files changed

+166
-5
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ PHP NEWS
33
?? ??? 2012, PHP 5.4.2
44

55
- CLI Server:
6+
. Implemented FR #61977 (Need CLI web-server support for files with .htm &
7+
svg extensions). (Sixd, Laruence)
68
. Fixed bug #61546 (functions related to current script failed when chdir()
79
in cli sapi). (Laruence, [email protected])
810
. Improved performance while sending error page, this also fixed

sapi/cli/php_cli_server.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -251,15 +251,17 @@ static php_cli_server_http_reponse_status_code_pair template_map[] = {
251251
};
252252

253253
static php_cli_server_ext_mime_type_pair mime_type_map[] = {
254+
{ "html", "text/html" },
255+
{ "htm", "text/html" },
256+
{ "js", "text/javascript" },
257+
{ "css", "text/css" },
254258
{ "gif", "image/gif" },
255-
{ "png", "image/png" },
256-
{ "jpe", "image/jpeg" },
257259
{ "jpg", "image/jpeg" },
258260
{ "jpeg", "image/jpeg" },
259-
{ "css", "text/css" },
260-
{ "html", "text/html" },
261+
{ "png", "image/png" },
262+
{ "jpe", "image/jpeg" },
263+
{ "svg", "image/svg+xml" },
261264
{ "txt", "text/plain" },
262-
{ "js", "text/javascript" },
263265
{ NULL, NULL }
264266
};
265267

sapi/cli/tests/bug61977.phpt

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
--TEST--
2+
Bug #60159 (Router returns false, but POST is not passed to requested resource)
3+
--SKIPIF--
4+
<?php
5+
include "skipif.inc";
6+
?>
7+
--FILE--
8+
<?php
9+
include "php_cli_server.inc";
10+
php_cli_server_start('<?php ?>', true);
11+
$doc_root = __DIR__;
12+
13+
list($host, $port) = explode(':', PHP_CLI_SERVER_ADDRESS);
14+
$port = intval($port)?:80;
15+
16+
$fp = fsockopen($host, $port, $errno, $errstr, 0.5);
17+
if (!$fp) {
18+
die("connect failed");
19+
}
20+
21+
file_put_contents($doc_root . '/foo.html', '');
22+
if(fwrite($fp, <<<HEADER
23+
GET /foo.html HTTP/1.1
24+
Host: {$host}
25+
26+
27+
HEADER
28+
)) {
29+
while (!feof($fp)) {
30+
$text = fgets($fp);
31+
if (strncasecmp("Content-type:", $text, 13) == 0) {
32+
echo "foo.html => ", $text;
33+
}
34+
}
35+
}
36+
@unlink($doc_root . '/foo.html');
37+
fclose($fp);
38+
39+
40+
$fp = fsockopen($host, $port, $errno, $errstr, 0.5);
41+
if (!$fp) {
42+
die("connect failed");
43+
}
44+
file_put_contents($doc_root . '/foo.htm', '');
45+
if(fwrite($fp, <<<HEADER
46+
GET /foo.htm HTTP/1.1
47+
Host: {$host}
48+
49+
50+
HEADER
51+
)) {
52+
while (!feof($fp)) {
53+
$text = fgets($fp);
54+
if (strncasecmp("Content-type:", $text, 13) == 0) {
55+
echo "foo.htm => ", $text;
56+
}
57+
}
58+
}
59+
@unlink($doc_root . '/foo.htm');
60+
fclose($fp);
61+
62+
63+
$fp = fsockopen($host, $port, $errno, $errstr, 0.5);
64+
if (!$fp) {
65+
die("connect failed");
66+
}
67+
file_put_contents($doc_root . '/foo.svg', '');
68+
if(fwrite($fp, <<<HEADER
69+
GET /foo.svg HTTP/1.1
70+
Host: {$host}
71+
72+
73+
HEADER
74+
)) {
75+
while (!feof($fp)) {
76+
$text = fgets($fp);
77+
if (strncasecmp("Content-type:", $text, 13) == 0) {
78+
echo "foo.svg => ", $text;
79+
}
80+
}
81+
}
82+
@unlink($doc_root . '/foo.svg');
83+
fclose($fp);
84+
85+
$fp = fsockopen($host, $port, $errno, $errstr, 0.5);
86+
if (!$fp) {
87+
die("connect failed");
88+
}
89+
file_put_contents($doc_root . '/foo.css', '');
90+
if(fwrite($fp, <<<HEADER
91+
GET /foo.css HTTP/1.1
92+
Host: {$host}
93+
94+
95+
HEADER
96+
)) {
97+
while (!feof($fp)) {
98+
$text = fgets($fp);
99+
if (strncasecmp("Content-type:", $text, 13) == 0) {
100+
echo "foo.css => ", $text;
101+
}
102+
}
103+
}
104+
@unlink($doc_root . '/foo.css');
105+
fclose($fp);
106+
107+
$fp = fsockopen($host, $port, $errno, $errstr, 0.5);
108+
if (!$fp) {
109+
die("connect failed");
110+
}
111+
file_put_contents($doc_root . '/foo.js', '');
112+
if(fwrite($fp, <<<HEADER
113+
GET /foo.js HTTP/1.1
114+
Host: {$host}
115+
116+
117+
HEADER
118+
)) {
119+
while (!feof($fp)) {
120+
$text = fgets($fp);
121+
if (strncasecmp("Content-type:", $text, 13) == 0) {
122+
echo "foo.js => ", $text;
123+
}
124+
}
125+
}
126+
@unlink($doc_root . '/foo.js');
127+
fclose($fp);
128+
129+
$fp = fsockopen($host, $port, $errno, $errstr, 0.5);
130+
if (!$fp) {
131+
die("connect failed");
132+
}
133+
file_put_contents($doc_root . '/foo.png', '');
134+
if(fwrite($fp, <<<HEADER
135+
GET /foo.png HTTP/1.1
136+
Host: {$host}
137+
138+
139+
HEADER
140+
)) {
141+
while (!feof($fp)) {
142+
$text = fgets($fp);
143+
if (strncasecmp("Content-type:", $text, 13) == 0) {
144+
echo "foo.png => ", $text;
145+
}
146+
}
147+
}
148+
@unlink($doc_root . '/foo.png');
149+
fclose($fp);
150+
?>
151+
--EXPECTF--
152+
foo.html => Content-Type: text/html; charset=UTF-8
153+
foo.htm => Content-Type: text/html; charset=UTF-8
154+
foo.svg => Content-Type: image/svg+xml
155+
foo.css => Content-Type: text/css; charset=UTF-8
156+
foo.js => Content-Type: text/javascript; charset=UTF-8
157+
foo.png => Content-Type: image/png

0 commit comments

Comments
 (0)