fixes bug 331825 "Unable to do conditional gets via XMLHttpRequest with 1.5.0.1, works in 1.0.7" r=biesi sr=bzbarsky

This commit is contained in:
darin%meer.net 2006-06-23 00:49:40 +00:00
Родитель 03dbf842d0
Коммит b1554032ae
3 изменённых файлов: 57 добавлений и 1 удалений

Просмотреть файл

@ -245,6 +245,17 @@ nsHttpChannel::AsyncCall(nsAsyncCallback funcPtr)
return NS_DispatchToCurrentThread(event);
}
PRBool
nsHttpChannel::RequestIsConditional()
{
// Is our consumer issuing a conditional request?
return mRequestHead.PeekHeader(nsHttp::If_Modified_Since) ||
mRequestHead.PeekHeader(nsHttp::If_None_Match) ||
mRequestHead.PeekHeader(nsHttp::If_Unmodified_Since) ||
mRequestHead.PeekHeader(nsHttp::If_Match) ||
mRequestHead.PeekHeader(nsHttp::If_Range);
}
nsresult
nsHttpChannel::Connect(PRBool firstTime)
{
@ -1226,7 +1237,8 @@ nsHttpChannel::OpenCacheEntry(PRBool offline, PRBool *delayed)
// don't use the cache for other types of requests
return NS_OK;
}
else if (mRequestHead.PeekHeader(nsHttp::Range)) {
if (mRequestHead.PeekHeader(nsHttp::Range)) {
// we don't support caching for byte range requests initiated
// by our clients or via nsIResumableChannel.
// XXX perhaps we could munge their byte range into the cache
@ -1234,6 +1246,12 @@ nsHttpChannel::OpenCacheEntry(PRBool offline, PRBool *delayed)
return NS_OK;
}
if (RequestIsConditional()) {
// don't use the cache if our consumer is making a conditional request
// (see bug 331825).
return NS_OK;
}
GenerateCacheKey(cacheKey);
// Get a cache session with appropriate storage policy

Просмотреть файл

@ -143,6 +143,7 @@ private:
// AsyncCall may be used to call a member function asynchronously.
nsresult AsyncCall(nsAsyncCallback funcPtr);
PRBool RequestIsConditional();
nsresult Connect(PRBool firstTime = PR_TRUE);
nsresult AsyncAbort(nsresult status);
nsresult SetupTransaction();

Просмотреть файл

@ -0,0 +1,37 @@
var server;
var BUGID = "331825";
function handle_response(stream) {
var response = server.handler.headers("304 Not Modified") + "\r\n";
stream.write(response, response.length);
}
function TestListener() {
}
TestListener.prototype.onStartRequest = function(request, context) {
}
TestListener.prototype.onStopRequest = function(request, context, status) {
var channel = request.QueryInterface(Components.interfaces.nsIHttpChannel);
do_check_eq(channel.responseStatus, 304);
do_test_finished();
}
function run_test() {
// start server
server = new nsTestServ(4444);
server.handler["/bug" + BUGID] = handle_response;
server.startListening();
// make request
var channel =
Components.classes["@mozilla.org/network/io-service;1"].
getService(Components.interfaces.nsIIOService).
newChannel("http://localhost:4444/bug" + BUGID, null, null);
channel.QueryInterface(Components.interfaces.nsIHttpChannel);
channel.setRequestHeader("If-None-Match", "foobar", false);
channel.asyncOpen(new TestListener(), null);
do_test_pending();
}