bug61977.phpt 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. --TEST--
  2. Bug #61977 test CLI web-server support for Mime Type File extensions mapping
  3. --SKIPIF--
  4. <?php
  5. include "skipif.inc";
  6. ?>
  7. --FILE--
  8. <?php
  9. include "php_cli_server.inc";
  10. $doc_root = php_cli_server_start('<?php ?>', null)->docRoot;
  11. /*
  12. * If a Mime Type is added in php_cli_server.c, add it to this array and update
  13. * the EXPECTF section accordingly
  14. */
  15. $mimetypes = ['html', 'htm', 'svg', 'css', 'js', 'png', 'webm', 'ogv', 'ogg'];
  16. foreach ($mimetypes as $mimetype) {
  17. $host = PHP_CLI_SERVER_HOSTNAME;
  18. $fp = php_cli_server_connect();
  19. if (!$fp) die('Connect failed');
  20. file_put_contents($doc_root . "/foo.{$mimetype}", '');
  21. $header = <<<HEADER
  22. GET /foo.{$mimetype} HTTP/1.1
  23. Host: {$host}
  24. HEADER;
  25. if (fwrite($fp, $header)) {
  26. while (!feof($fp)) {
  27. $text = fgets($fp);
  28. if (strncasecmp("Content-type:", $text, 13) == 0) {
  29. echo "foo.{$mimetype} => ", $text;
  30. }
  31. }
  32. @unlink($doc_root . "/foo.{$mimetype}");
  33. fclose($fp);
  34. }
  35. }
  36. ?>
  37. --EXPECT--
  38. foo.html => Content-Type: text/html; charset=UTF-8
  39. foo.htm => Content-Type: text/html; charset=UTF-8
  40. foo.svg => Content-Type: image/svg+xml
  41. foo.css => Content-Type: text/css; charset=UTF-8
  42. foo.js => Content-Type: application/javascript
  43. foo.png => Content-Type: image/png
  44. foo.webm => Content-Type: video/webm
  45. foo.ogv => Content-Type: video/ogg
  46. foo.ogg => Content-Type: audio/ogg