Skip to content

Update list of common Mime Types in PHP development server #239

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion sapi/cli/php_cli_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -259,10 +259,13 @@ static php_cli_server_ext_mime_type_pair mime_type_map[] = {
{ "gif", "image/gif" },
{ "jpg", "image/jpeg" },
{ "jpeg", "image/jpeg" },
{ "png", "image/png" },
{ "jpe", "image/jpeg" },
{ "png", "image/png" },
{ "svg", "image/svg+xml" },
{ "txt", "text/plain" },
{ "webm", "video/webm" },
{ "ogv", "video/ogg" },
{ "ogg", "audio/ogg" },
{ NULL, NULL }
};

Expand Down
164 changes: 31 additions & 133 deletions sapi/cli/tests/bug61977.phpt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--TEST--
Bug #61977 (Need CLI web-server support for files with .htm & svg extensions)
Bug #61977 test CLI web-server support for Mime Type File extensions mapping
--SKIPIF--
<?php
include "skipif.inc";
Expand All @@ -8,145 +8,40 @@ include "skipif.inc";
<?php
include "php_cli_server.inc";
php_cli_server_start('<?php ?>', true);
$doc_root = __DIR__;

list($host, $port) = explode(':', PHP_CLI_SERVER_ADDRESS);
$port = intval($port)?:80;

$fp = fsockopen($host, $port, $errno, $errstr, 0.5);
if (!$fp) {
die("connect failed");
}

file_put_contents($doc_root . '/foo.html', '');
if(fwrite($fp, <<<HEADER
GET /foo.html HTTP/1.1
Host: {$host}


HEADER
)) {
while (!feof($fp)) {
$text = fgets($fp);
if (strncasecmp("Content-type:", $text, 13) == 0) {
echo "foo.html => ", $text;
}
}
}
@unlink($doc_root . '/foo.html');
fclose($fp);


$fp = fsockopen($host, $port, $errno, $errstr, 0.5);
if (!$fp) {
die("connect failed");
}
file_put_contents($doc_root . '/foo.htm', '');
if(fwrite($fp, <<<HEADER
GET /foo.htm HTTP/1.1
Host: {$host}


HEADER
)) {
while (!feof($fp)) {
$text = fgets($fp);
if (strncasecmp("Content-type:", $text, 13) == 0) {
echo "foo.htm => ", $text;
}
}
}
@unlink($doc_root . '/foo.htm');
fclose($fp);


$fp = fsockopen($host, $port, $errno, $errstr, 0.5);
if (!$fp) {
die("connect failed");
}
file_put_contents($doc_root . '/foo.svg', '');
if(fwrite($fp, <<<HEADER
GET /foo.svg HTTP/1.1
/*
* If a Mime Type is added in php_cli_server.c, add it to this array and update
* the EXPECTF section accordingly
*/
$mimetypes = ['html', 'htm', 'svg', 'css', 'js', 'png', 'webm', 'ogv', 'ogg'];

function test_mimetypes($mimetypes) {
foreach ($mimetypes as $mimetype) {
list($host, $port) = explode(':', PHP_CLI_SERVER_ADDRESS);
$port = intval($port) ? : 80;
$fp = fsockopen($host, $port, $errno, $errstr, 0.5);
if (!$fp) die('Connect failed');
file_put_contents(__DIR__ . "/foo.{$mimetype}", '');
$header = <<<HEADER
GET /foo.{$mimetype} HTTP/1.1
Host: {$host}


HEADER
)) {
while (!feof($fp)) {
$text = fgets($fp);
if (strncasecmp("Content-type:", $text, 13) == 0) {
echo "foo.svg => ", $text;
HEADER;
if (fwrite($fp, $header)) {
while (!feof($fp)) {
$text = fgets($fp);
if (strncasecmp("Content-type:", $text, 13) == 0) {
echo "foo.{$mimetype} => ", $text;
}
}
@unlink(__DIR__ . "/foo.{$mimetype}");
fclose($fp);
}
}
}
}
@unlink($doc_root . '/foo.svg');
fclose($fp);

$fp = fsockopen($host, $port, $errno, $errstr, 0.5);
if (!$fp) {
die("connect failed");
}
file_put_contents($doc_root . '/foo.css', '');
if(fwrite($fp, <<<HEADER
GET /foo.css HTTP/1.1
Host: {$host}


HEADER
)) {
while (!feof($fp)) {
$text = fgets($fp);
if (strncasecmp("Content-type:", $text, 13) == 0) {
echo "foo.css => ", $text;
}
}
}
@unlink($doc_root . '/foo.css');
fclose($fp);

$fp = fsockopen($host, $port, $errno, $errstr, 0.5);
if (!$fp) {
die("connect failed");
}
file_put_contents($doc_root . '/foo.js', '');
if(fwrite($fp, <<<HEADER
GET /foo.js HTTP/1.1
Host: {$host}


HEADER
)) {
while (!feof($fp)) {
$text = fgets($fp);
if (strncasecmp("Content-type:", $text, 13) == 0) {
echo "foo.js => ", $text;
}
}
}
@unlink($doc_root . '/foo.js');
fclose($fp);

$fp = fsockopen($host, $port, $errno, $errstr, 0.5);
if (!$fp) {
die("connect failed");
}
file_put_contents($doc_root . '/foo.png', '');
if(fwrite($fp, <<<HEADER
GET /foo.png HTTP/1.1
Host: {$host}


HEADER
)) {
while (!feof($fp)) {
$text = fgets($fp);
if (strncasecmp("Content-type:", $text, 13) == 0) {
echo "foo.png => ", $text;
}
}
}
@unlink($doc_root . '/foo.png');
fclose($fp);
test_mimetypes($mimetypes);
?>
--EXPECTF--
foo.html => Content-Type: text/html; charset=UTF-8
Expand All @@ -155,3 +50,6 @@ foo.svg => Content-Type: image/svg+xml
foo.css => Content-Type: text/css; charset=UTF-8
foo.js => Content-Type: text/javascript; charset=UTF-8
foo.png => Content-Type: image/png
foo.webm => Content-Type: video/webm
foo.ogv => Content-Type: video/ogg
foo.ogg => Content-Type: audio/ogg