Ver código fonte

Add test for HTTP method handling

bel 10 anos atrás
pai
commit
971310a422
1 arquivos alterados com 145 adições e 0 exclusões
  1. 145 0
      test/MethodTest.xhtml

+ 145 - 0
test/MethodTest.xhtml

@@ -0,0 +1,145 @@
+<!DOCTYPE HTML>
+<html xmlns="http://www.w3.org/1999/xhtml"><head>
+<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
+  <title>HTTP method test</title>
+  <style type="text/css" media="screen">
+    body {background:#eee; margin:0%; padding:0%; padding-top:0%; padding-left:1%}
+    .cform {margin:0%; padding:0%; padding-top:0%; padding-left:2%;}
+    h3 {margin:0%; padding:0%; padding-top:0%; padding-left:0%;}
+  </style>
+  <script type="text/javascript"><![CDATA[
+
+    function getParams() {
+      var result = {};
+      var kvPairs = location.search.slice(1).split('&');
+
+      kvPairs.forEach(
+        function(kvPair) {
+          kvPair = kvPair.split('=');
+          result[kvPair[0]] = kvPair[1] || '';
+        }
+      );
+
+      return result;
+    }
+
+    function load() {
+        var params = getParams();
+        method = params["method"];
+        if (!method) {
+          method = "GET";
+        }
+
+        var elem = document.getElementById('h1');
+        elem.innerHTML = "HTTP method test page";
+
+        document.getElementById("proto_http").checked = (window.location.protocol != "https:");
+        document.getElementById("proto_https").checked = (window.location.protocol == "https:");
+        document.getElementById("server").value = location.host;
+        document.getElementById("resource").value = "path";
+
+        document.getElementById("method_get").checked = true;
+        document.getElementById("body_none").checked = true;
+    }
+
+    function getRadioValue(elmname) {
+
+      var elms = document.getElementsByName(elmname);
+      var len = elms.length;
+      var ret = "";
+
+      for (var i=0; i<len; i++) {
+        if (elms[i].checked) {
+          ret = elms[i].value;
+        }
+      }
+      return ret;
+    }
+
+    function sendreq() {
+        var proto = getRadioValue("protocol");
+        var host = document.getElementById("server").value;
+        var res = document.getElementById("resource").value;
+        var addr = proto + "://" + host + "/" + res;
+        var meth = getRadioValue("method");
+        var body = getRadioValue("body");
+
+        xmlhttp = new XMLHttpRequest();
+        if (!xmlhttp) {
+          alert("XMLHttpRequest not available");
+          window.history.back()
+        }
+
+        xmlhttp.open(meth,addr,true);
+
+        if (body != '*') {
+          xmlhttp.setRequestHeader("Content-Length", body.length);
+        } else {
+          body = null;
+        }
+
+        xmlhttp.onreadystatechange = function()
+        {
+            var laddr = addr
+            var lmeth = meth
+            var blen = "\nWith " + body.length + " bytes body data"
+            
+            if (xmlhttp.readyState == 4)
+            {
+                alert(lmeth + " " + laddr + blen + "\n\nResponse: " + xmlhttp.status + "\n\n" + xmlhttp.responseText);
+            }
+        }
+
+        xmlhttp.send(body);
+
+    }
+
+  ]]></script>
+
+</head><body onload="load()">
+
+<h1 id='h1'>Fatal error: Javascript not available!</h1>
+<h2>Usage</h2>
+
+<p>
+TODO: Description how to use this page.
+</p>
+
+<h2>Test parameters</h2>
+<form lass="cform">
+
+<h3>Protocol</h3>
+<input id="proto_http" type="radio" name="protocol" value="http" />http <br />
+<input id="proto_https" type="radio" name="protocol" value="https" />https
+
+<h3>Server</h3>
+<input id="server" type="text" name="server" value="" />
+
+<h3>Resource</h3>
+<input id="resource" type="text" name="resource" value="" />
+
+<h3>Method</h3>
+<!-- http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html -->
+<input id="method_opt" type="radio" name="method" value="OPTIONS" />OPTIONS <br />
+<input id="method_get" type="radio" name="method" value="GET" />GET <br />
+<input id="method_hea" type="radio" name="method" value="HEAD" />HEAD <br />
+<input id="method_pos" type="radio" name="method" value="POST" />POST <br />
+<input id="method_put" type="radio" name="method" value="PUT" />PUT <br />
+<input id="method_del" type="radio" name="method" value="DELETE" />DELETE <br />
+<input id="method_tra" type="radio" name="method" value="TRACE" />TRACE <br />
+<input id="method_con" type="radio" name="method" value="CONNECT" />CONNECT <br />
+<input id="method_mkc" type="radio" name="method" value="MKCOL" />MKCOL <br />
+<input id="method_pro" type="radio" name="method" value="PROPFIND" />PROPFIND <br />
+<input id="method_inv" type="radio" name="method" value="INVALID" />*INVALID*
+
+<h3>Body data</h3>
+<input id="body_none" type="radio" name="body" value="*" />*none* <br />
+<input id="body_10" type="radio" name="body" value="1234567890" />1234567890 <br />
+
+
+<h3>Submit</h3>
+<input id="send" type="button" onclick="sendreq()" value="Send request" />
+
+</form>
+
+</body></html>