send-entity-body-none.htm (2015B)
1 <!doctype html> 2 <html> 3 <head> 4 <title>XMLHttpRequest: send(null) - no entity body</title> 5 <script src="/resources/testharness.js"></script> 6 <script src="/resources/testharnessreport.js"></script> 7 <link rel="help" href="https://xhr.spec.whatwg.org/#the-send()-method" data-tested-assertations="following::ol[1]/li[4] following::ol[1]/li[7]" /> 8 </head> 9 <body> 10 <div id="log"></div> 11 <script> 12 function noContentTypeTest(method) { 13 var client = new XMLHttpRequest() 14 client.open(method, "resources/content.py", false) 15 client.upload.onloadstart = function(){assert_unreached('this event should not fire for null')} 16 client.send(null) 17 var expectedLength = method == "HEAD" ? "NO" : "0"; 18 assert_equals(client.getResponseHeader("x-request-content-length"), expectedLength) 19 assert_equals(client.getResponseHeader("x-request-content-type"), "NO") 20 } 21 test(function() { noContentTypeTest("POST"); }, "No content type (POST)"); 22 test(function() { noContentTypeTest("PUT"); }, "No content type (PUT)"); 23 test(function() { noContentTypeTest("HEAD"); }, "No content type (HEAD)"); 24 25 function explicitContentTypeTest(method) { 26 var client = new XMLHttpRequest() 27 client.open(method, "resources/content.py", false) 28 var content_type = 'application/x-foo' 29 client.setRequestHeader('Content-Type', content_type) 30 client.send(null) 31 var expectedLength = method == "HEAD" ? "NO" : "0"; 32 assert_equals(client.getResponseHeader("x-request-content-length"), expectedLength) 33 assert_equals(client.getResponseHeader("x-request-content-type"), content_type) 34 } 35 test(function() { explicitContentTypeTest("POST"); }, "Explicit content type (POST)"); 36 test(function() { explicitContentTypeTest("PUT"); }, "Explicit content type (PUT)"); 37 test(function() { explicitContentTypeTest("HEAD"); }, "Explicit content type (HEAD)"); 38 </script> 39 </body> 40 </html>