browser(firefox): fix uploads of large files in Firefox (#6547)
- to read post data of requests, we have to read stream - to restore the stream later on, we have to rewind it back - however, if the stream is large enough, it cannot be rewound back This patch starts cloning post data streams if possible to avoid back-rewinding them later on. References #4704
This commit is contained in:
parent
1a39843df5
commit
d02472a9e0
|
|
@ -1,2 +1,2 @@
|
||||||
1250
|
1251
|
||||||
Changed: yurys@chromium.org Wed 12 May 2021 08:53:32 AM PDT
|
Changed: lushnikov@chromium.org Wed 12 May 2021 04:13:18 PM PDT
|
||||||
|
|
|
||||||
|
|
@ -740,11 +740,17 @@ function getSecurityDetails(httpChannel) {
|
||||||
function readRequestPostData(httpChannel) {
|
function readRequestPostData(httpChannel) {
|
||||||
if (!(httpChannel instanceof Ci.nsIUploadChannel))
|
if (!(httpChannel instanceof Ci.nsIUploadChannel))
|
||||||
return undefined;
|
return undefined;
|
||||||
const iStream = httpChannel.uploadStream;
|
let iStream = httpChannel.uploadStream;
|
||||||
if (!iStream)
|
if (!iStream)
|
||||||
return undefined;
|
return undefined;
|
||||||
const isSeekableStream = iStream instanceof Ci.nsISeekableStream;
|
const isSeekableStream = iStream instanceof Ci.nsISeekableStream;
|
||||||
|
|
||||||
|
// For some reason, we cannot rewind back big streams,
|
||||||
|
// so instead we should clone them.
|
||||||
|
const isCloneable = iStream instanceof Ci.nsICloneableInputStream;
|
||||||
|
if (isCloneable)
|
||||||
|
iStream = iStream.clone();
|
||||||
|
|
||||||
let prevOffset;
|
let prevOffset;
|
||||||
if (isSeekableStream) {
|
if (isSeekableStream) {
|
||||||
prevOffset = iStream.tell();
|
prevOffset = iStream.tell();
|
||||||
|
|
@ -767,7 +773,7 @@ function readRequestPostData(httpChannel) {
|
||||||
// Seek locks the file, so seek to the beginning only if necko hasn't
|
// Seek locks the file, so seek to the beginning only if necko hasn't
|
||||||
// read it yet, since necko doesn't seek to 0 before reading (at lest
|
// read it yet, since necko doesn't seek to 0 before reading (at lest
|
||||||
// not till 459384 is fixed).
|
// not till 459384 is fixed).
|
||||||
if (isSeekableStream && prevOffset == 0)
|
if (isSeekableStream && prevOffset == 0 && !isCloneable)
|
||||||
iStream.seek(Ci.nsISeekableStream.NS_SEEK_SET, 0);
|
iStream.seek(Ci.nsISeekableStream.NS_SEEK_SET, 0);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,2 +1,2 @@
|
||||||
1260
|
1261
|
||||||
Changed: yurys@chromium.org Wed 12 May 2021 08:49:17 AM PDT
|
Changed: lushnikov@chromium.org Wed 12 May 2021 04:12:52 PM PDT
|
||||||
|
|
|
||||||
|
|
@ -740,11 +740,17 @@ function getSecurityDetails(httpChannel) {
|
||||||
function readRequestPostData(httpChannel) {
|
function readRequestPostData(httpChannel) {
|
||||||
if (!(httpChannel instanceof Ci.nsIUploadChannel))
|
if (!(httpChannel instanceof Ci.nsIUploadChannel))
|
||||||
return undefined;
|
return undefined;
|
||||||
const iStream = httpChannel.uploadStream;
|
let iStream = httpChannel.uploadStream;
|
||||||
if (!iStream)
|
if (!iStream)
|
||||||
return undefined;
|
return undefined;
|
||||||
const isSeekableStream = iStream instanceof Ci.nsISeekableStream;
|
const isSeekableStream = iStream instanceof Ci.nsISeekableStream;
|
||||||
|
|
||||||
|
// For some reason, we cannot rewind back big streams,
|
||||||
|
// so instead we should clone them.
|
||||||
|
const isCloneable = iStream instanceof Ci.nsICloneableInputStream;
|
||||||
|
if (isCloneable)
|
||||||
|
iStream = iStream.clone();
|
||||||
|
|
||||||
let prevOffset;
|
let prevOffset;
|
||||||
if (isSeekableStream) {
|
if (isSeekableStream) {
|
||||||
prevOffset = iStream.tell();
|
prevOffset = iStream.tell();
|
||||||
|
|
@ -767,7 +773,7 @@ function readRequestPostData(httpChannel) {
|
||||||
// Seek locks the file, so seek to the beginning only if necko hasn't
|
// Seek locks the file, so seek to the beginning only if necko hasn't
|
||||||
// read it yet, since necko doesn't seek to 0 before reading (at lest
|
// read it yet, since necko doesn't seek to 0 before reading (at lest
|
||||||
// not till 459384 is fixed).
|
// not till 459384 is fixed).
|
||||||
if (isSeekableStream && prevOffset == 0)
|
if (isSeekableStream && prevOffset == 0 && !isCloneable)
|
||||||
iStream.seek(Ci.nsISeekableStream.NS_SEEK_SET, 0);
|
iStream.seek(Ci.nsISeekableStream.NS_SEEK_SET, 0);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue