11.2.08
8.2.08
Update: AskApache Password Protect Plugin
read more | digg story
5.2.08
XMLHttpRequest and Basic Authentication
If the
readyStateattribute has a value other than 1 (Open), anINVALID_STATE_ERRexception must be raised. Otherwise, a request to url using method method is sent. url, if relative, must be resolved usingwindow.document.baseURIof thewindowwhose constructor is used. If the async flag is set to false, then the method must not return until the request has completed. Otherwise, it must return immediately. (See:open().)If data is passed to the
send()method it must be used for the entity body following these rules (the term entity body is defined by section 7.2.1 of [RFC2616]):- If data is a
DOMString, it must be encoded as UTF-8 for transmission. - If the data is a
Document, it must be serialized using the encoding given bydata.xmlEncoding, if specified and supported, or UTF-8 otherwise [DOM3Core]. - If data is not a
DOMStringor aDocumentthe host language its stringification mechanisms must be used on the argument that was passed and the result must be treated as if data is aDOMString.
Invoking
send()without the data argument must give the same result as if it was invoked withnullas argument.Authors should specify the
Content-Typeheader viasetRequestHeaderbefore invokingsend()with an argument. If the argument tosend()is aDocumentand noContent-Typeheader has been set user agents must set it toapplication/xmlfor XML documents and to the most appropriate media type for other documents (using intrinsic knowledge about the document).If the response is an HTTP redirect (status code
301,302,303or307), then it must be transparently followed (unless it violates security, infinite loop precautions or the scheme isn't supported). Note that HTTP ([RFC2616]) places requirements on user agents regarding the preservation of the request method during redirects, and also requires users to be notified of certain kinds of automatic redirections.Once the request has been successfully acknowledged
readyStatemust be set to 2 (Sent). Immediately before receiving the message body (if any), thereadyStateattribute must be set to to 3 (Receiving). When the request has completed loading, thereadyStateattribute must be set to 4 (Loaded). In case of aHEADrequestreadyStatemust be set to 4 (Loaded) immediately after having gone to 3 (Receiving).If something goes wrong (infinite loop, network errors) the
readyStateattribute must be set to 4 (Loaded) and all other members of the object must be set to their initial value.In future versions of this specification user agents will be required to dispatch an
errorevent if the above occurs.If the user agent allows the specification of a proxy it should modify the request appropriately; i.e., connect to the proxy host instead of the origin server, modify the
Request-Lineand sendProxy-Authorizationheaders as specified.If the user agent supports HTTP Authentication ([RFC2617]) it should consider requests originating from this object to be part of the protection space that includes the accessed URIs and send
Authorizationheaders and handle401 Unauthorisedrequests appropriately. if authentication fails, user agents should prompt the users for credentials.If the user agent supports HTTP State Mangement ([RFC2109], [RFC2965]) it should persist, discard and send cookies (as received in the
Set-CookieandSet-Cookie2response headers, and sent in theCookieheader) as applicable.If the user agent implements a HTTP cache ([RFC2616]) it should respect
Cache-Controlrequest headers set by the author (e.g.,Cache-Control: no-cachebypasses the cache). It must not sendCache-ControlorPragmarequest headers automatically unless the user explicitly requests such behaviour (e.g., by (force-)reloading the page).304 Not Modifiedresponses that are a result of a user agent generated conditional request must be presented as200 OKresponses with the appropriate content. Such user agents must allow authors to override automatic cache validation by setting request headers (e.g.,If-None-Match,If-Modified-Since), in which case304 Not Modifiedresponses must be passed through.If the user agent implements server-driven content-negotiation ([RFC2616]) it should set
Accept-Language,Accept-EncodingandAccept-Charsetheaders as appropriate; it must not automatically set theAcceptheader. Responses to such requests must have content-codings automatically removed.If the user agent supports Expect/Continue for request bodies ([RFC2616]) it should insert
Expectheaders and handle100 Continueresponses appropriately.- If data is a
abort(), method-
When invoked, this method must cancel any network activity for which the object is responsible and set all the members of the object to their initial values.
getAllResponseHeaders(), method-
If the
readyStateattribute has a value other than 3 (Receiving) or 4 (Loaded), user agents must raise anINVALID_STATE_ERRexception. Otherwise, it must return all the HTTP headers, as a single string, with each header line separated by a CR (U+000D) LF (U+000A) pair. The status line must not be included.// The following script:
var client = new XMLHttpRequest();
client.open("GET", "test.txt", true);
client.send();
client.onreadystatechange = function() {
if(this.readyState == 3) {
print(this.getAllResponseHeaders());
}
}
// ...should output something similar to the following text:
Date: Sun, 24 Oct 2004 04:58:38 GMT
Server: Apache/1.3.31 (Unix)
Keep-Alive: timeout=15, max=99
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: text/plain; charset=utf-8 getResponseHeader(header), method-
If the header argument doesn't match the
field-nameproduction aSYNTAX_ERRmust be raised. Otherwise this method works as described below.If the
readyStateattribute has a value other than 3 (Receiving) or 4 (Loaded), the user agent must raise anINVALID_STATE_ERRexception. Otherwise, it must represent the value of the given HTTP header (header) in the data received so far for the last request sent, as a single string. If more than one header of the given name was received, then the values must be concatenated, separated from each other by an U+002C COMMA followed by an U+0020 SPACE. If no headers of that name were received, then it must returnnull. Header names must be compared case-insensitively to the method its argument (header).// The following script:
var client = new XMLHttpRequest();
client.open("GET", "test.txt", true);
client.send();
client.onreadystatechange = function() {
if(this.readyState == 3) {
print(client.getResponseHeader("Content-Type"));
}
}
// ...should output something similar to the following text:
Content-Type: text/plain; charset=utf-8 responseTextof typeDOMString, readonly-
If the
readyStateattribute has a value other than 3 (Receiving) or 4 (Loaded), the user agent must raise anINVALID_STATE_ERRexception. Otherwise, it must be the fragment of the entity body received so far (whenreadyStateis 3 (Receiving)) or the complete entity body (whenreadyStateis 4 (Loaded)), interpreted as a stream of characters.If the response includes a
Content-Typeunderstood by the user agent the characters are encoded following the relevant media type specification, with the exception that the rule in the final paragraph of section 3.7.1 of [RFC2616], and the rules in section 4.1.2 of [RFC2046] must be treated as if they specified the default character encoding as being UTF-8. Invalid bytes must be converted to U+FFFD REPLACEMENT CHARACTER. If the user agent can't derive a character stream in accord with the media type specification,reponseTextmust benull.