xref: /php-src/sapi/cli/tests/bug61977.phpt (revision 6ab4e330)
1--TEST--
2Bug #61977 test CLI web-server support for Mime Type File extensions mapping
3--SKIPIF--
4<?php
5include "skipif.inc";
6?>
7--FILE--
8<?php
9include "php_cli_server.inc";
10$doc_root = php_cli_server_start('<?php ?>', null)->docRoot;
11
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
18foreach ($mimetypes as $mimetype) {
19    $host = PHP_CLI_SERVER_HOSTNAME;
20    $fp = php_cli_server_connect();
21    if (!$fp) die('Connect failed');
22    file_put_contents($doc_root . "/foo.{$mimetype}", '');
23    $header = <<<HEADER
24GET /foo.{$mimetype} HTTP/1.1
25Host: {$host}
26
27
28HEADER;
29    if (fwrite($fp, $header)) {
30        while (!feof($fp)) {
31            $text = fgets($fp);
32            if (strncasecmp("Content-type:", $text, 13) == 0) {
33                echo "foo.{$mimetype} => ", $text;
34            }
35        }
36        @unlink($doc_root . "/foo.{$mimetype}");
37        fclose($fp);
38    }
39}
40
41?>
42--EXPECT--
43foo.html => Content-Type: text/html; charset=UTF-8
44foo.htm => Content-Type: text/html; charset=UTF-8
45foo.svg => Content-Type: image/svg+xml
46foo.css => Content-Type: text/css; charset=UTF-8
47foo.js => Content-Type: application/javascript
48foo.png => Content-Type: image/png
49foo.webm => Content-Type: video/webm
50foo.ogv => Content-Type: video/ogg
51foo.ogg => Content-Type: audio/ogg
52