Skip to content

Commit aaa5e42

Browse files
committed
Merge branch 'PHP-5.4' into PHP-5.5
2 parents a73a6be + c3b4803 commit aaa5e42

File tree

2 files changed

+35
-134
lines changed

2 files changed

+35
-134
lines changed

sapi/cli/php_cli_server.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,10 +259,13 @@ static php_cli_server_ext_mime_type_pair mime_type_map[] = {
259259
{ "gif", "image/gif" },
260260
{ "jpg", "image/jpeg" },
261261
{ "jpeg", "image/jpeg" },
262-
{ "png", "image/png" },
263262
{ "jpe", "image/jpeg" },
263+
{ "png", "image/png" },
264264
{ "svg", "image/svg+xml" },
265265
{ "txt", "text/plain" },
266+
{ "webm", "video/webm" },
267+
{ "ogv", "video/ogg" },
268+
{ "ogg", "audio/ogg" },
266269
{ NULL, NULL }
267270
};
268271

sapi/cli/tests/bug61977.phpt

Lines changed: 31 additions & 133 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--TEST--
2-
Bug #61977 (Need CLI web-server support for files with .htm & svg extensions)
2+
Bug #61977 test CLI web-server support for Mime Type File extensions mapping
33
--SKIPIF--
44
<?php
55
include "skipif.inc";
@@ -8,145 +8,40 @@ include "skipif.inc";
88
<?php
99
include "php_cli_server.inc";
1010
php_cli_server_start('<?php ?>', true);
11-
$doc_root = __DIR__;
1211

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
12+
/*
13+
* If a Mime Type is added in php_cli_server.c, add it to this array and update
14+
* the EXPECTF section accordingly
15+
*/
16+
$mimetypes = ['html', 'htm', 'svg', 'css', 'js', 'png', 'webm', 'ogv', 'ogg'];
17+
18+
function test_mimetypes($mimetypes) {
19+
foreach ($mimetypes as $mimetype) {
20+
list($host, $port) = explode(':', PHP_CLI_SERVER_ADDRESS);
21+
$port = intval($port) ? : 80;
22+
$fp = fsockopen($host, $port, $errno, $errstr, 0.5);
23+
if (!$fp) die('Connect failed');
24+
file_put_contents(__DIR__ . "/foo.{$mimetype}", '');
25+
$header = <<<HEADER
26+
GET /foo.{$mimetype} HTTP/1.1
7027
Host: {$host}
7128
7229
73-
HEADER
74-
)) {
75-
while (!feof($fp)) {
76-
$text = fgets($fp);
77-
if (strncasecmp("Content-type:", $text, 13) == 0) {
78-
echo "foo.svg => ", $text;
30+
HEADER;
31+
if (fwrite($fp, $header)) {
32+
while (!feof($fp)) {
33+
$text = fgets($fp);
34+
if (strncasecmp("Content-type:", $text, 13) == 0) {
35+
echo "foo.{$mimetype} => ", $text;
36+
}
37+
}
38+
@unlink(__DIR__ . "/foo.{$mimetype}");
39+
fclose($fp);
7940
}
80-
}
41+
}
8142
}
82-
@unlink($doc_root . '/foo.svg');
83-
fclose($fp);
8443

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);
44+
test_mimetypes($mimetypes);
15045
?>
15146
--EXPECTF--
15247
foo.html => Content-Type: text/html; charset=UTF-8
@@ -155,3 +50,6 @@ foo.svg => Content-Type: image/svg+xml
15550
foo.css => Content-Type: text/css; charset=UTF-8
15651
foo.js => Content-Type: text/javascript; charset=UTF-8
15752
foo.png => Content-Type: image/png
53+
foo.webm => Content-Type: video/webm
54+
foo.ogv => Content-Type: video/ogg
55+
foo.ogg => Content-Type: audio/ogg

0 commit comments

Comments
 (0)