Raw File
setrequestheader-invalid-arguments.htm
<!doctype html>
<html>
  <head>
    <title>XMLHttpRequest: setRequestHeader() with invalid arguments</title>
    <script src="/resources/testharness.js"></script>
    <script src="/resources/testharnessreport.js"></script>
  </head>
  <body>
    <div id="log"></div>
<!--
       CHAR           = <any US-ASCII character (octets 0 - 127)>
       CTL            = <any US-ASCII control character
                        (octets 0 - 31) and DEL (127)>
       SP             = <US-ASCII SP, space (32)>
       HT             = <US-ASCII HT, horizontal-tab (9)>
       token          = 1*<any CHAR except CTLs or separators>
       separators     = "(" | ")" | "<" | ">" | "@"
                      | "," | ";" | ":" | "\" | <">
                      | "/" | "[" | "]" | "?" | "="
                      | "{" | "}" | SP | HT
       field-name     = token
-->
    <script>
      var invalid_headers = ["(", ")", "<", ">", "@", ",", ";", ":", "\\",
                             "\"", "/", "[", "]", "?", "=", "{", "}", " ",
                             /* HT already tested in the loop below */
                             "\u007f"]
      for (var i = 0; i < 32; ++i) {
        invalid_headers.push(String.fromCharCode(i))
      }
      for (var i = 0; i < invalid_headers.length; ++i) {
        test(function() {
          assert_throws("SyntaxError", function() {
            var client = new XMLHttpRequest()
            client.open("GET", "../common/text-plain.txt")
            client.setRequestHeader(invalid_headers[i], "test")
          })
        }, "setRequestHeader should throw with header " +
           format_value(invalid_headers[i]) + ".")
      }
    </script>
  </body>
</html>
back to top