PageRenderTime 40ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/third_party/WebKit/LayoutTests/http/tests/inspector/network/resources/resource.php

https://gitlab.com/jonnialva90/iridium-browser
PHP | 119 lines | 100 code | 10 blank | 9 comment | 36 complexity | 19da6a81c433c01e2def1ab2bb79f478 MD5 | raw file
  1. <?php
  2. $type = $_GET["type"];
  3. $wait = $_GET["wait"];
  4. $send = $_GET["send"];
  5. $size = $_GET["size"];
  6. $gzip = $_GET["gzip"];
  7. $jsdelay = $_GET["jsdelay"];
  8. $jscontent = $_GET["jscontent"];
  9. $chunked = $_GET["chunked"];
  10. $random = $_GET["random"];
  11. $cached = $_GET["cached"];
  12. # Wait before sending response
  13. if ($wait)
  14. usleep($wait * 1000);
  15. # Exit early if we return 304 code.
  16. if ($cached && $_SERVER["HTTP_IF_MODIFIED_SINCE"]) {
  17. header("HTTP/1.0 304 Not Modified");
  18. exit;
  19. }
  20. # Enable gzip compression if needed
  21. if ($gzip)
  22. ob_start("ob_gzhandler");
  23. # Send headers
  24. if ($cached) {
  25. $max_age = 12 * 31 * 24 * 60 * 60; //one year
  26. $expires = gmdate(DATE_RFC1123, time() + $max_age);
  27. $last_modified = gmdate(DATE_RFC1123, time() - $max_age);
  28. header("Cache-Control: public, max-age=" . 5*$max_age);
  29. header("Cache-control: max-age=0");
  30. header("Expires: " . $expires);
  31. header("Last-Modified: " . $last_modified);
  32. } else {
  33. header("Expires: Thu, 01 Dec 2003 16:00:00 GMT");
  34. header("Cache-Control: no-store, no-cache, must-revalidate");
  35. header("Pragma: no-cache");
  36. }
  37. if ($type == "js")
  38. header("Content-Type:text/javascript; charset=UTF-8");
  39. else if ($type == "image")
  40. header("Content-Type: image/png");
  41. else
  42. header("Content-Type: text/plain");
  43. # Flush headers and sleep bofore sending response
  44. if ($send) {
  45. flush();
  46. usleep($send * 1000);
  47. }
  48. if ($type == "js") {
  49. # Send JavaScript file
  50. $bytes_emitted = 0;
  51. if ($jsdelay) {
  52. # JavaScript file should block on load
  53. ?>
  54. function __foo(seconds) {
  55. var now = Date.now();
  56. var counter = Number(0);
  57. while(now + seconds > Date.now()) { counter = Number(counter + 1); }
  58. }
  59. __foo(<?php echo($jsdelay)?>);
  60. <?php
  61. $bytes_emitted += 175;
  62. }
  63. if (!$jscontent)
  64. $jscontent = "function foo() {}";
  65. # JavaScript file should issue given command.
  66. echo($jscontent);
  67. $bytes_emitted += strlen($jscontent);
  68. if ($size) {
  69. for ($i = 0; $i < $size - $bytes_emitted; ++$i)
  70. echo("/");
  71. }
  72. } else if ($type == "image") {
  73. $base64data = "iVBORw0KGgoAAAANSUhEUgAAACAAAAAYCAYAAACbU/80AAAAAXNSR0IArs4c6QAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9kICQsw" .
  74. "ARCJCogAAABFSURBVEjH7ZLBCQAwCAONdP+V0xVqq0gx9w+Gi2ZCTAcXGWbe8G4Dq9DekS" .
  75. "kPaGeFgfYJVODlCTnWADILoEg3vplACLEBN9UGG9+mxboAAAAASUVORK5CYII=";
  76. $data = base64_decode($base64data);
  77. $data_len = strlen($data);
  78. print($data);
  79. if ($size) {
  80. if ($chunked) {
  81. ob_flush();
  82. flush();
  83. }
  84. for ($i = 0; $size && $i < $size - $data_len; ++$i)
  85. echo("=");
  86. } else if ($random)
  87. echo(rand());
  88. } else {
  89. # Generate dummy text/html.
  90. if ($size) {
  91. for ($i = 0; $i < $size; ++$i) {
  92. if ($chunked && (1 == $i)) {
  93. ob_flush();
  94. flush();
  95. }
  96. echo("*");
  97. }
  98. } else {
  99. echo("Hello ");
  100. if ($chunked) {
  101. ob_flush();
  102. flush();
  103. }
  104. echo("world");
  105. if ($random)
  106. echo(": " . rand());
  107. }
  108. }
  109. ?>