1
1
--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
3
3
--SKIPIF--
4
4
<?php
5
5
include "skipif.inc " ;
@@ -8,145 +8,40 @@ include "skipif.inc";
8
8
<?php
9
9
include "php_cli_server.inc " ;
10
10
php_cli_server_start ('<?php ?> ' , true );
11
- $ doc_root = __DIR__ ;
12
11
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
70
27
Host: {$ host }
71
28
72
29
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 );
79
40
}
80
- }
41
+ }
81
42
}
82
- @unlink ($ doc_root . '/foo.svg ' );
83
- fclose ($ fp );
84
43
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 );
150
45
?>
151
46
--EXPECTF--
152
47
foo.html => Content-Type: text/html; charset=UTF-8
@@ -155,3 +50,6 @@ foo.svg => Content-Type: image/svg+xml
155
50
foo.css => Content-Type: text/css; charset=UTF-8
156
51
foo.js => Content-Type: text/javascript; charset=UTF-8
157
52
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