-
-
Notifications
You must be signed in to change notification settings - Fork 35.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FileLoader: Add response headers to onProgress callback #23896
FileLoader: Add response headers to onProgress callback #23896
Conversation
src/loaders/FileLoader.js
Outdated
for ( let i = 0, il = callbacks.length; i < il; i ++ ) { | ||
|
||
const callback = callbacks[ i ]; | ||
if ( callback.onProgress ) callback.onProgress( event ); | ||
if ( callback.onProgress ) callback.onProgress( event, response.headers ); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm thinking instead of creating a ProgressEvent
instance we just create a custom object with the information we want in the object. Something like:
const event = {
lengthComputable,
loaded,
total,
response,
};
There's no reason the passed object has to be a ProgressEvent
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can it be const event = new ProgressEvent( 'progress', { lengthComputable, loaded, total, response } );
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No from the docs "response" is not a valid field for ProgressEvent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, yes... Then the object approach is better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That'd be great as well. Let me know if I should make the change, then I can change the docs accordingly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can start with a custom object and if someone complains we fallback to the initial approach of the PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed it to a custom object including the response and I also updated the docs.
c53e97e
to
31558d0
Compare
This has been fixed by #24971. |
Unfortunately my previous comment was a bit too soon. For compressed files the compressed file size is sent with the To solve our issue, either the X-File-Size header needs to take precedence, or we would still need this PR. |
Description
Since #22510 the response headers can't be accessed anymore in the progress callback. A custom response header can be used to send the uncompressed content length of large compressed files (gzip, brotli) to report loading progress to the user. The
total
content length currently reported by theProgressEvent
, is the content length of the compressed file and theloaded
bytes are currently reported for the uncompressed file loading progress of theReadableStream
. Even with the new Fetch API, this is still an unresolved issue: whatwg/fetch#1358.Before the Fetch API was introduced, the
onProgress
callback received the XMLHttpRequest object as the event target, which gave access to the response headers.This PR adds the response headers as an argument to the
onProgress
callback to provide access to the response headers again.