MethodTest.xhtml 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. <!DOCTYPE HTML>
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
  5. <title>HTTP method test</title>
  6. <style type="text/css" media="screen">
  7. body {background:#eee; margin:0%; padding:0%; padding-top:0%; padding-left:1%}
  8. .cform {margin:0%; padding:0%; padding-top:0%; padding-left:2%;}
  9. h3 {margin:0%; padding:0%; padding-top:0%; padding-left:0%;}
  10. td {vertical-align:top; text-align:left;}
  11. </style>
  12. <script type="text/javascript"><![CDATA[
  13. function getParams() {
  14. var result = {};
  15. var kvPairs = location.search.slice(1).split('&');
  16. kvPairs.forEach(
  17. function(kvPair) {
  18. kvPair = kvPair.split('=');
  19. result[kvPair[0]] = kvPair[1] || '';
  20. }
  21. );
  22. return result;
  23. }
  24. function noBody() {
  25. document.getElementById("body_none").checked = true;
  26. }
  27. function load() {
  28. var params = getParams();
  29. var method = params["method"];
  30. if (!method) {
  31. method = "GET";
  32. }
  33. var path = params["path"];
  34. if (!path) {
  35. path = "";
  36. }
  37. var elem = document.getElementById('h1');
  38. elem.innerHTML = "HTTP method test page";
  39. document.getElementById("proto_http").checked = (window.location.protocol != "https:");
  40. document.getElementById("proto_https").checked = (window.location.protocol == "https:");
  41. document.getElementById("server").value = location.host;
  42. document.getElementById("resource").value = path;
  43. setRadioValue("method", method);
  44. noBody();
  45. }
  46. function setRadioValue(elmname, value) {
  47. var elms = document.getElementsByName(elmname);
  48. var len = elms.length;
  49. var ret = false;
  50. for (var i=0; i<len; i++) {
  51. elms[i].checked = (elms[i].value == value);
  52. ret |= elms[i].checked;
  53. }
  54. return ret;
  55. }
  56. function getRadioValue(elmname) {
  57. var elms = document.getElementsByName(elmname);
  58. var len = elms.length;
  59. var ret = "";
  60. for (var i=0; i<len; i++) {
  61. if (elms[i].checked) {
  62. ret = elms[i].value;
  63. }
  64. }
  65. return ret;
  66. }
  67. function sendreq() {
  68. var proto = getRadioValue("protocol");
  69. var host = document.getElementById("server").value;
  70. var res = document.getElementById("resource").value;
  71. var addr = proto + "://" + host + "/" + res;
  72. var meth = getRadioValue("method");
  73. var body = getRadioValue("body");
  74. xmlhttp = new XMLHttpRequest();
  75. if (!xmlhttp) {
  76. alert("XMLHttpRequest not available");
  77. window.history.back();
  78. }
  79. xmlhttp.open(meth,addr,true);
  80. if (body == '*') {
  81. body = null;
  82. } else {
  83. if (body == '**') {
  84. var body_bytes = document.getElementById("body_bytes").value;
  85. body_bytes = parseInt(Number(body_bytes) || 0) || 0;
  86. body = "";
  87. for (var i=0; i<body_bytes; i++) {
  88. var ascii = Math.floor((Math.random() * 94) + 32);
  89. body = body + String.fromCharCode(ascii);
  90. }
  91. }
  92. xmlhttp.setRequestHeader("Content-Length", body.length);
  93. }
  94. xmlhttp.onreadystatechange = function()
  95. {
  96. var laddr = addr;
  97. var lmeth = meth;
  98. var blen = "";
  99. if (body) {
  100. blen = "\nWith " + body.length + " bytes body data";
  101. }
  102. if (xmlhttp.readyState == 4)
  103. {
  104. alert(lmeth + " " + laddr + blen + "\n\nResponse: " + xmlhttp.status + "\n\n" + xmlhttp.responseText);
  105. }
  106. }
  107. xmlhttp.send(body);
  108. }
  109. ]]></script>
  110. </head>
  111. <body onload="load()">
  112. <h1 id='h1'>Fatal error: Javascript not available!</h1>
  113. <h2>Test parameters</h2>
  114. <form lass="cform">
  115. <h3>Protocol</h3>
  116. <input id="proto_http" type="radio" name="protocol" value="http" /> http <br />
  117. <input id="proto_https" type="radio" name="protocol" value="https" /> https
  118. <h3>Server/Host</h3>
  119. <input id="server" type="text" name="server" value="" />
  120. <h3>Resource</h3>
  121. <input id="resource" type="text" name="resource" value="" />
  122. <h3>Method</h3>
  123. <!-- http://www.restpatterns.org/HTTP_Methods -->
  124. <!-- http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html -->
  125. <table style="border-spacing:15px 0px;">
  126. <tr>
  127. <td><a href="http://tools.ietf.org/html/rfc7231#section-4.2.1">Save Methods</a></td>
  128. <td>"Unsave" <a href="http://tools.ietf.org/html/rfc7231#section-4.2.2">Idempotent Methods</a></td>
  129. <td>Non-Idempotent Methods</td>
  130. <td>Special</td>
  131. </tr>
  132. <tr>
  133. <td>
  134. <input id="method_opt" type="radio" name="method" value="OPTIONS" onclick="noBody()" /> OPTIONS <br />
  135. <input id="method_get" type="radio" name="method" value="GET" onclick="noBody()" /> GET <br />
  136. <input id="method_hea" type="radio" name="method" value="HEAD" onclick="noBody()" /> HEAD <br />
  137. <input id="method_tra" type="radio" name="method" value="TRACE" /> TRACE <br />
  138. <input id="method_pro" type="radio" name="method" value="PROPFIND" /> PROPFIND <br />
  139. </td>
  140. <td>
  141. <input id="method_put" type="radio" name="method" value="PUT" /> PUT <br />
  142. <input id="method_del" type="radio" name="method" value="DELETE" /> DELETE <br />
  143. <input id="method_cop" type="radio" name="method" value="COPY" /> COPY <br />
  144. <input id="method_cop" type="radio" name="method" value="MOVE" /> MOVE <br />
  145. <input id="method_ppa" type="radio" name="method" value="PROPPATCH" /> PROPPATCH <br />
  146. <input id="method_unl" type="radio" name="method" value="UNLOCK" /> UNLOCK <br />
  147. </td>
  148. <td>
  149. <input id="method_pos" type="radio" name="method" value="POST" /> POST <br />
  150. <input id="method_pat" type="radio" name="method" value="PATCH" /> PATCH <br />
  151. <input id="method_mkc" type="radio" name="method" value="MKCOL" /> MKCOL <br />
  152. <input id="method_loc" type="radio" name="method" value="LOCK" /> LOCK <br />
  153. </td>
  154. <td>
  155. <input id="method_con" type="radio" name="method" value="CONNECT" /> CONNECT <br />
  156. <input id="method_userdef" type="radio" name="method" value="INVALID" /> <input id="method_name" type="text" name="method_name" value="INVALID" oninput="var elem = document.getElementById('method_userdef'); elem.checked = true; elem.value=value" /> <br />
  157. </td>
  158. </tr>
  159. </table>
  160. <h3>Body data</h3>
  161. <input id="body_none" type="radio" name="body" value="*" /> No body data <br />
  162. <input id="body_10" type="radio" name="body" value="1234567890" /> 10 Bytes ("1234567890") <br />
  163. <input id="body_rnd" type="radio" name="body" value="**" /> <input id="body_bytes" type="number" name="body_bytes" value="100" min="0" step="0" max="999999999" oninput="document.getElementById('body_rnd').checked = true" /> Bytes random data <br />
  164. <h3>Submit</h3>
  165. <input id="send" type="button" onclick="sendreq()" value="Send request" />
  166. </form>
  167. </body></html>