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