<div>I realized that the HTTP response headers exposed in the <a href="http://www.w3.org/html/wg/html5/#htmldocument">HTMLDocument interface</a> are limited: referrer, cookie, lastModified, charset, characterSet.<br><br>It would be very useful if a script could get *all* of the response headers, the raw entity body, and the HTTP status: basically it would be great if the HTMLDocument interface implemented a subset of of the XMLHttpRequest spec, namely the parts which have to do with the response (e.g. getAllResponseHeaders(), getResponseHeader(), status, and others which appear below). The HTMLDocument interface already has a readyState property which XMLHttpRequest also has, but the HTMLDocument interface lacks XHR's onreadystatechange attribute.<br>
<br>If this subset were implemented on HTMLDocument, then scripts would be able to determine if the page if a 404 or get any other arbitrary information that is passed in the response header.<br><br>Here's a proposed extension to the HTMLDocument interface with some comments to explain the semantics:<br>
<br><span style="font-family: courier new,monospace;">interface HTMLDocument {<br>  ...<br>  //another way to get DOMContentLoaded event; the readyState would start out as LOADING<br>  attribute EventListener onreadystatechange;<br>
 <br>  // state<br>  const unsigned short UNSENT = 0;<br>  const unsigned short OPENED = 1;<br>  const unsigned short HEADERS_RECEIVED = 2;<br>  const unsigned short LOADING = 3;<br>  const unsigned short DONE = 4;<br>  readonly attribute unsigned short readyState; //already in HTML 5<br>
 <br>  // request<br>  void abort(); //complements window.stop(): stops the contained document instead of the associated resources<br> <br>  // response<br>  DOMString getAllResponseHeaders();<br>  DOMString getResponseHeader(in DOMString header);<br>
  readonly attribute DOMString responseText; //the non-parsed content of the document<br>  readonly attribute Document responseXML;<br>  readonly attribute unsigned short status;<br>  readonly attribute DOMString statusText;<br>
}</span><br><br></div>