mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-27 23:02:20 +00:00
Bug 398069 - Don't cancel resume-from-0 transfers for HTTP 200 responses. r=biesi, sr= biesi, a=sayrer
This commit is contained in:
parent
79e39ea1b8
commit
a89e870995
@ -803,7 +803,8 @@ nsHttpChannel::ProcessResponse()
|
||||
// Per RFC 2616, 14.35.2, "A server MAY ignore the Range header".
|
||||
// So if a server does that and sends 200 instead of 206 that we
|
||||
// expect, notify our caller.
|
||||
if (mResuming) {
|
||||
// However, if we wanted to start from the beginning, let it go through
|
||||
if (mResuming && mStartPos != 0) {
|
||||
LOG(("Server ignored our Range header, cancelling [this=%p]\n", this));
|
||||
Cancel(NS_ERROR_NOT_RESUMABLE);
|
||||
rv = CallOnStartRequest();
|
||||
@ -917,7 +918,8 @@ nsHttpChannel::ProcessNormal()
|
||||
// If creating an entity id is not possible -> error
|
||||
Cancel(NS_ERROR_NOT_RESUMABLE);
|
||||
}
|
||||
else if (mResponseHead->Status() != 206) {
|
||||
else if (mResponseHead->Status() != 206 &&
|
||||
mResponseHead->Status() != 200) {
|
||||
// Probably 404 Not Found, 412 Precondition Failed or
|
||||
// 416 Invalid Range -> error
|
||||
LOG(("Unexpected response status while resuming, aborting [this=%p]\n",
|
||||
|
@ -87,18 +87,29 @@ function run_test() {
|
||||
chan.nsIResumableChannel.resumeAt(1, entityID);
|
||||
chan.asyncOpen(new ChannelListener(try_resume, null, CL_EXPECT_FAILURE), null);
|
||||
}
|
||||
|
||||
function try_resume(request, data, ctx) {
|
||||
do_check_eq(request.status, NS_ERROR_NOT_RESUMABLE);
|
||||
|
||||
// Try a successful resume
|
||||
var chan = make_channel("http://localhost:4444/range");
|
||||
chan.nsIResumableChannel.resumeAt(1, entityID);
|
||||
chan.asyncOpen(new ChannelListener(try_resume_zero, null), null);
|
||||
}
|
||||
|
||||
function try_resume_zero(request, data, ctx) {
|
||||
do_check_true(request.nsIHttpChannel.requestSucceeded);
|
||||
do_check_eq(data, rangeBody.substring(1));
|
||||
|
||||
// Try a successful resume from 0
|
||||
var chan = make_channel("http://localhost:4444/range");
|
||||
chan.nsIResumableChannel.resumeAt(0, entityID);
|
||||
chan.asyncOpen(new ChannelListener(success, null), null);
|
||||
}
|
||||
|
||||
function success(request, data, ctx) {
|
||||
do_check_true(request.nsIHttpChannel.requestSucceeded);
|
||||
do_check_eq(data, rangeBody.substring(1));
|
||||
do_check_eq(data, rangeBody);
|
||||
|
||||
// Authentication (no password; working resume)
|
||||
// (should not give us any data)
|
||||
@ -251,10 +262,9 @@ function rangeHandler(metadata, response) {
|
||||
return;
|
||||
}
|
||||
body = body.substring(from, to + 1);
|
||||
if (body.length != rangeBody.length) {
|
||||
response.setStatusLine(metadata.httpVersion, 206, "Partial Content");
|
||||
response.setHeader("Content-Range", from + "-" + to + "/" + rangeBody.length);
|
||||
}
|
||||
// always respond to successful range requests with 206
|
||||
response.setStatusLine(metadata.httpVersion, 206, "Partial Content");
|
||||
response.setHeader("Content-Range", from + "-" + to + "/" + rangeBody.length);
|
||||
}
|
||||
|
||||
response.bodyOutputStream.write(body, body.length);
|
||||
|
Loading…
Reference in New Issue
Block a user