protocol: respect range header when reading from asar
This commit is contained in:
parent
1ae7b2fcbc
commit
bd291b9601
2 changed files with 32 additions and 42 deletions
|
@ -44,6 +44,7 @@ URLRequestAsarJob::URLRequestAsarJob(
|
||||||
: net::URLRequestJob(request, network_delegate),
|
: net::URLRequestJob(request, network_delegate),
|
||||||
type_(TYPE_ERROR),
|
type_(TYPE_ERROR),
|
||||||
remaining_bytes_(0),
|
remaining_bytes_(0),
|
||||||
|
seek_offset_(0),
|
||||||
range_parse_result_(net::OK),
|
range_parse_result_(net::OK),
|
||||||
weak_ptr_factory_(this) {}
|
weak_ptr_factory_(this) {}
|
||||||
|
|
||||||
|
@ -100,8 +101,6 @@ void URLRequestAsarJob::InitializeFileJob(
|
||||||
|
|
||||||
void URLRequestAsarJob::Start() {
|
void URLRequestAsarJob::Start() {
|
||||||
if (type_ == TYPE_ASAR) {
|
if (type_ == TYPE_ASAR) {
|
||||||
remaining_bytes_ = static_cast<int64_t>(file_info_.size);
|
|
||||||
|
|
||||||
int flags = base::File::FLAG_OPEN |
|
int flags = base::File::FLAG_OPEN |
|
||||||
base::File::FLAG_READ |
|
base::File::FLAG_READ |
|
||||||
base::File::FLAG_ASYNC;
|
base::File::FLAG_ASYNC;
|
||||||
|
@ -274,17 +273,16 @@ void URLRequestAsarJob::DidOpen(int result) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int64_t file_size, read_offset;
|
||||||
if (type_ == TYPE_ASAR) {
|
if (type_ == TYPE_ASAR) {
|
||||||
int rv = stream_->Seek(file_info_.offset,
|
file_size = file_info_.size;
|
||||||
base::Bind(&URLRequestAsarJob::DidSeek,
|
read_offset = file_info_.offset;
|
||||||
weak_ptr_factory_.GetWeakPtr()));
|
|
||||||
if (rv != net::ERR_IO_PENDING) {
|
|
||||||
// stream_->Seek() failed, so pass an intentionally erroneous value
|
|
||||||
// into DidSeek().
|
|
||||||
DidSeek(-1);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if (!byte_range_.ComputeBounds(meta_info_.file_size)) {
|
file_size = meta_info_.file_size;
|
||||||
|
read_offset = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!byte_range_.ComputeBounds(file_size)) {
|
||||||
NotifyStartError(
|
NotifyStartError(
|
||||||
net::URLRequestStatus(net::URLRequestStatus::FAILED,
|
net::URLRequestStatus(net::URLRequestStatus::FAILED,
|
||||||
net::ERR_REQUEST_RANGE_NOT_SATISFIABLE));
|
net::ERR_REQUEST_RANGE_NOT_SATISFIABLE));
|
||||||
|
@ -293,9 +291,10 @@ void URLRequestAsarJob::DidOpen(int result) {
|
||||||
|
|
||||||
remaining_bytes_ = byte_range_.last_byte_position() -
|
remaining_bytes_ = byte_range_.last_byte_position() -
|
||||||
byte_range_.first_byte_position() + 1;
|
byte_range_.first_byte_position() + 1;
|
||||||
|
seek_offset_ = byte_range_.first_byte_position() + read_offset;
|
||||||
|
|
||||||
if (remaining_bytes_ > 0 && byte_range_.first_byte_position() != 0) {
|
if (remaining_bytes_ > 0 && seek_offset_ != 0) {
|
||||||
int rv = stream_->Seek(byte_range_.first_byte_position(),
|
int rv = stream_->Seek(seek_offset_,
|
||||||
base::Bind(&URLRequestAsarJob::DidSeek,
|
base::Bind(&URLRequestAsarJob::DidSeek,
|
||||||
weak_ptr_factory_.GetWeakPtr()));
|
weak_ptr_factory_.GetWeakPtr()));
|
||||||
if (rv != net::ERR_IO_PENDING) {
|
if (rv != net::ERR_IO_PENDING) {
|
||||||
|
@ -307,27 +306,17 @@ void URLRequestAsarJob::DidOpen(int result) {
|
||||||
// We didn't need to call stream_->Seek() at all, so we pass to DidSeek()
|
// We didn't need to call stream_->Seek() at all, so we pass to DidSeek()
|
||||||
// the value that would mean seek success. This way we skip the code
|
// the value that would mean seek success. This way we skip the code
|
||||||
// handling seek failure.
|
// handling seek failure.
|
||||||
DidSeek(byte_range_.first_byte_position());
|
DidSeek(seek_offset_);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void URLRequestAsarJob::DidSeek(int64_t result) {
|
void URLRequestAsarJob::DidSeek(int64_t result) {
|
||||||
if (type_ == TYPE_ASAR) {
|
if (result != seek_offset_) {
|
||||||
if (result != static_cast<int64_t>(file_info_.offset)) {
|
|
||||||
NotifyStartError(
|
NotifyStartError(
|
||||||
net::URLRequestStatus(net::URLRequestStatus::FAILED,
|
net::URLRequestStatus(net::URLRequestStatus::FAILED,
|
||||||
net::ERR_REQUEST_RANGE_NOT_SATISFIABLE));
|
net::ERR_REQUEST_RANGE_NOT_SATISFIABLE));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
if (result != byte_range_.first_byte_position()) {
|
|
||||||
NotifyStartError(
|
|
||||||
net::URLRequestStatus(net::URLRequestStatus::FAILED,
|
|
||||||
net::ERR_REQUEST_RANGE_NOT_SATISFIABLE));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
set_expected_content_size(remaining_bytes_);
|
set_expected_content_size(remaining_bytes_);
|
||||||
NotifyHeadersComplete();
|
NotifyHeadersComplete();
|
||||||
}
|
}
|
||||||
|
|
|
@ -118,6 +118,7 @@ class URLRequestAsarJob : public net::URLRequestJob {
|
||||||
|
|
||||||
net::HttpByteRange byte_range_;
|
net::HttpByteRange byte_range_;
|
||||||
int64_t remaining_bytes_;
|
int64_t remaining_bytes_;
|
||||||
|
int64_t seek_offset_;
|
||||||
|
|
||||||
net::Error range_parse_result_;
|
net::Error range_parse_result_;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue