OLD | NEW |
(Empty) | |
| 1 <!doctype html> |
| 2 <html> |
| 3 <head> |
| 4 <meta charset="utf-8"> |
| 5 <title>Request Headers</title> |
| 6 <meta name="help" href="https://fetch.spec.whatwg.org/#request"> |
| 7 <meta name="author" title="Canon Research France" href="https://www.crf.cano
n.fr"> |
| 8 <script src="/resources/testharness.js"></script> |
| 9 <script src="/resources/testharnessreport.js"></script> |
| 10 </head> |
| 11 <body> |
| 12 <script> |
| 13 var validRequestHeaders = [ |
| 14 ["Content-Type", "OK"], |
| 15 ["Potato", "OK"], |
| 16 ["proxy", "OK"], |
| 17 ["proxya", "OK"], |
| 18 ["sec", "OK"], |
| 19 ["secb", "OK"], |
| 20 ]; |
| 21 var invalidRequestHeaders = [ |
| 22 ["Accept-Charset", "KO"], |
| 23 ["accept-charset", "KO"], |
| 24 ["ACCEPT-ENCODING", "KO"], |
| 25 ["Accept-Encoding", "KO"], |
| 26 ["Access-Control-Request-Headers", "KO"], |
| 27 ["Access-Control-Request-Method", "KO"], |
| 28 ["Connection", "KO"], |
| 29 ["Content-Length", "KO"], |
| 30 ["Cookie", "KO"], |
| 31 ["Cookie2", "KO"], |
| 32 ["Date", "KO"], |
| 33 ["DNT", "KO"], |
| 34 ["Expect", "KO"], |
| 35 ["Host", "KO"], |
| 36 ["Keep-Alive", "KO"], |
| 37 ["Origin", "KO"], |
| 38 ["Referer", "KO"], |
| 39 ["TE", "KO"], |
| 40 ["Trailer", "KO"], |
| 41 ["Transfer-Encoding", "KO"], |
| 42 ["Upgrade", "KO"], |
| 43 ["Via", "KO"], |
| 44 ["Proxy-", "KO"], |
| 45 ["proxy-a", "KO"], |
| 46 ["Sec-", "KO"], |
| 47 ["sec-b", "KO"], |
| 48 ]; |
| 49 |
| 50 var validRequestNoCorsHeaders = [ |
| 51 ["Accept", "OK"], |
| 52 ["Accept-Language", "OK"], |
| 53 ["content-language", "OK"], |
| 54 ["content-type", "application/x-www-form-urlencoded"], |
| 55 ["content-type", "application/x-www-form-urlencoded;charset=UTF-8"], |
| 56 ["content-type", "multipart/form-data"], |
| 57 ["content-type", "multipart/form-data;charset=UTF-8"], |
| 58 ["content-TYPE", "text/plain"], |
| 59 ["CONTENT-type", "text/plain;charset=UTF-8"], |
| 60 ]; |
| 61 var invalidRequestNoCorsHeaders = [ |
| 62 ["Content-Type", "KO"], |
| 63 ["Potato", "KO"], |
| 64 ["proxy", "KO"], |
| 65 ["proxya", "KO"], |
| 66 ["sec", "KO"], |
| 67 ["secb", "KO"], |
| 68 ]; |
| 69 |
| 70 validRequestHeaders.forEach(function(header) { |
| 71 test(function() { |
| 72 var request = new Request(""); |
| 73 request.headers.set(header[0], header[1]); |
| 74 assert_equals(request.headers.get(header[0]), header[1]); |
| 75 }, "Adding valid request header \"" + header[0] + ": " + header[1] + "\"
"); |
| 76 }); |
| 77 invalidRequestHeaders.forEach(function(header) { |
| 78 test(function() { |
| 79 var request = new Request(""); |
| 80 request.headers.set(header[0], header[1]); |
| 81 assert_equals(request.headers.get(header[0]), null); |
| 82 }, "Adding invalid request header \"" + header[0] + ": " + header[1] + "
\""); |
| 83 }); |
| 84 |
| 85 validRequestNoCorsHeaders.forEach(function(header) { |
| 86 test(function() { |
| 87 var requestNoCors = new Request("", {"mode": "no-cors"}); |
| 88 requestNoCors.headers.set(header[0], header[1]); |
| 89 assert_equals(requestNoCors.headers.get(header[0]), header[1]); |
| 90 }, "Adding valid no-cors request header \"" + header[0] + ": " + header[
1] + "\""); |
| 91 }); |
| 92 invalidRequestNoCorsHeaders.forEach(function(header) { |
| 93 test(function() { |
| 94 var requestNoCors = new Request("", {"mode": "no-cors"}); |
| 95 requestNoCors.headers.set(header[0], header[1]); |
| 96 assert_equals(requestNoCors.headers.get(header[0]), null); |
| 97 }, "Adding invalid no-cors request header \"" + header[0] + ": " + heade
r[1] + "\""); |
| 98 }); |
| 99 |
| 100 test(function() { |
| 101 var headers = new Headers([["Cookie2", "potato"]]); |
| 102 var request = new Request("", {"headers": headers}); |
| 103 assert_equals(request.headers.get("Cookie2"), null); |
| 104 }, "Check that request constructor is filtering headers provided as init p
arameter"); |
| 105 |
| 106 test(function() { |
| 107 var headers = new Headers([["Content-Type", "potato"]]); |
| 108 var request = new Request("", {"headers": headers, "mode": "no-cors"}); |
| 109 assert_equals(request.headers.get("Content-Type"), null); |
| 110 }, "Check that no-cors request constructor is filtering headers provided a
s init parameter"); |
| 111 |
| 112 test(function() { |
| 113 var headers = new Headers([["Content-Type", "potato"]]); |
| 114 var initialRequest = new Request("", {"headers": headers}); |
| 115 var request = new Request(initialRequest, {"mode": "no-cors"}); |
| 116 assert_equals(request.headers.get("Content-Type"), null); |
| 117 }, "Check that no-cors request constructor is filtering headers provided a
s part of request parameter"); |
| 118 |
| 119 test(function() { |
| 120 var initialHeaders = new Headers([["Content-Type", "potato"]]); |
| 121 var initialRequest = new Request("", {"headers" : initialHeaders}); |
| 122 var request = new Request(initialRequest); |
| 123 assert_equals(request.headers.get("Content-Type"), "potato"); |
| 124 }, "Request should get its content-type from the init request"); |
| 125 |
| 126 test(function() { |
| 127 var initialHeaders = new Headers([["Content-Type", "potato"]]); |
| 128 var initialRequest = new Request("", {"headers" : initialHeaders}); |
| 129 var headers = new Headers([]); |
| 130 var request = new Request(initialRequest, {"headers" : headers}); |
| 131 assert_false(request.headers.has("Content-Type")); |
| 132 }, "Request should not get its content-type from the init request if init
headers are provided"); |
| 133 |
| 134 test(function() { |
| 135 var initialHeaders = new Headers([["Content-Type-Extra", "potato"]]); |
| 136 var initialRequest = new Request("", {"headers" : initialHeaders, "body"
: "this is my plate", "method" : "POST"}); |
| 137 var request = new Request(initialRequest); |
| 138 assert_equals(request.headers.get("Content-Type"), "text/plain;charset=U
TF-8"); |
| 139 }, "Request should get its content-type from the body if none is provided"
); |
| 140 |
| 141 test(function() { |
| 142 var initialHeaders = new Headers([["Content-Type", "potato"]]); |
| 143 var initialRequest = new Request("", {"headers" : initialHeaders, "body"
: "this is my plate", "method" : "POST"}); |
| 144 var request = new Request(initialRequest); |
| 145 assert_equals(request.headers.get("Content-Type"), "potato"); |
| 146 }, "Request should get its content-type from init headers if one is provid
ed"); |
| 147 |
| 148 test(function() { |
| 149 var array = [["hello", "worldAHH"]]; |
| 150 var object = {"hello": 'worldOOH'}; |
| 151 var headers = new Headers(array); |
| 152 |
| 153 assert_equals(headers.get("hello"), "worldAHH"); |
| 154 |
| 155 var request1 = new Request("", {"headers": headers}); |
| 156 var request2 = new Request("", {"headers": array}); |
| 157 var request3 = new Request("", {"headers": object}); |
| 158 |
| 159 assert_equals(request1.headers.get("hello"), "worldAHH"); |
| 160 assert_equals(request2.headers.get("hello"), "worldAHH"); |
| 161 assert_equals(request3.headers.get("hello"), "worldOOH"); |
| 162 }, "Testing request header creations with various objects"); |
| 163 |
| 164 promise_test(function(test) { |
| 165 var request = new Request("", {"headers" : [["Content-Type", ""]], "body
" : "this is my plate", "method" : "POST"}); |
| 166 return request.blob().then(function(blob) { |
| 167 assert_equals(blob.type, "", "Blob type should be the empty string"); |
| 168 }); |
| 169 }, "Testing empty Request Content-Type header"); |
| 170 |
| 171 </script> |
| 172 </body> |
| 173 </html> |
OLD | NEW |