Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upGitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
Adds CORS support (XDomainRequest) for IE7+ still through XMLHttpRequest #107
Conversation
| request.onload = () => { | ||
| resolve(response()); | ||
| request.onreadystatechange = function() { | ||
| if(this.readyState === 4 && this.status === 200) { |
developit
Jan 9, 2019
Owner
this.status check here should be removed. we only care that readyState is 4.
this.status check here should be removed. we only care that readyState is 4.
3F
Jan 9, 2019
Author
whoops, I leaved this from my described hack in #106 :)
For my personal task, readystate = 4 will be also triggered on CORS errors and for abort operations.
that is status = 0 for readystate = 4
wait
whoops, I leaved this from my described hack in #106 :)
For my personal task, readystate = 4 will be also triggered on CORS errors and for abort operations.
that is status = 0 for readystate = 4
wait
|
Let us return to our muttons :)
I was still worried about your statement about removing Today I've checked implementation of XHR, specially to check this moment because I was not sure about fully equivalent to load events for just However, seems my first thought that appeared from my example #106 (well, exactly from my mentioned task), was initially a correct thought. So I'm not agree with you :) I'll illustrate possible bug via Firefox: We will initialize onreadystatechange via
basically the only Before final processing I'm also seeing decoding response and finally changing state and dispatching our additional events there are many places that we will raise after, but mainly, this is what I'm talking about: XMLHttpRequestMainThread::ChangeStateToDone()
{
...
if (mErrorLoad != ErrorType::eOK) {
DispatchProgressEvent(this, ProgressEventType::error, 0, -1);
} else {
DispatchProgressEvent(this, ProgressEventType::load,
mLoadTransferred, mLoadTotal);
}when, for example: void
XMLHttpRequestMainThread::CloseRequest()
{
mWaitingForOnStopRequest = false;
mErrorLoad = ErrorType::eTerminated;
if (mChannel) {
mChannel->Cancel(NS_BINDING_ABORTED);
}when, for example: void
XMLHttpRequestMainThread::TerminateOngoingFetch() {
if ((mState == XMLHttpRequest_Binding::OPENED && mFlagSend) ||
mState == XMLHttpRequest_Binding::HEADERS_RECEIVED ||
mState == XMLHttpRequest_Binding::LOADING) {
CloseRequest();
}
}and so on ... Thus! we will never have processing for onload events (javascript) when processing the same failed state for onreadystatechange (javascript) That is, as I understand from this code, the readyState === 4 && status !== 0Or more probably(I've not inspected a lot), I'm seeing many places for changing status, like status from http channel via all overrided virtual methods MOZ_MUST_USE NS_IMETHOD GetResponseStatus(uint32_t *aResponseStatus) = 0;and other, but seems Unfortunately, I still can't find official documentation for compare logic Please check this out, again. I'll try also to prepare a common example later if needed (javascript of course) to reproduce this behavior. |
|
I'm still here, and this is my explanation via javascript now: let xhr = new XMLHttpRequest();
window.XMLHttpRequest.prototype.xD = function(evt)
{
console.log(evt, this.readyState, this.status);
}
xhr.onreadystatechange = function()
{
if(this.readyState !== 4) return;
xhr.xD('readystatechange()');
}
xhr.onload = () => xhr.xD('load()');
xhr.onabort = () => xhr.xD('abort()');
xhr.open('GET', 'https://api.github.com/users/3F/repos');
xhr.send();
// readystatechange() 4 200
// load() 4 200
setTimeout(() => xhr.abort(), 100);
// readystatechange() 4 0 <<<<<<<
// abort() 4 0
xhr.open('GET', 'https://api.github.com/users/3F/NULL');
xhr.send();
// readystatechange() 4 404
// load() 4 404
xhr.abort();
// readystatechange() 4 0 <<<<<<<
// abort() 4 0So I'm thinking at least for non 0 state :p Or I need to inspect more via original implementation (C++ src see above). For chromium etc please check it yourself. I will not. Any related official doc/RFC is really appreciated. Because it maybe just a bug of engines (I'm not sure because I have no info), like: // The ChangeState call above calls onreadystatechange handlers which
// if they load a new url will cause XMLHttpRequestMainThread::Open to clear
// the abort state bit. If this occurs we're not uninitialized (bug 361773).
if (mFlagAborted) {
ChangeState(XMLHttpRequest_Binding::UNSENT, false); // IE seems to do it
} |
…r `load` event, here: #107
|
Fully reviewed an In addition to my explanation in #107, here's also testing of states for different http codes together with an abort operations: ...
let sleep = (ms) => {
return new Promise(_ => setTimeout(_, ms))
}
let vrf = async(code, abort = false, srvsleep = 1000) =>
{
console.log('==== ' + code + ' : abort = ' + abort);
xhr.open('GET', 'https://httpstat.us/' + code + '?sleep=' + srvsleep, true);
xhr.send();
if(abort)
{
await sleep(500);
xhr.abort();
return;
}
let attempt = 0;
while(xhr.readyState !== 4)
{
if(++attempt > 20) {
console.log('Stop waiting an readyState. /' + xhr.readyState);
return;
}
await sleep(250);
}
}
let xhrTest = async (errors, delay = 1000) =>
{
for(let err of errors)
{
await sleep(delay);
await vrf(err, false);
await sleep(delay);
await vrf(err, true);
}
}
xhrTest([100, 101, 102, 200, 201, 202, 203, 204, 205, 206, 300, 301, 302, 303, 304, 305, 306, 307, 308, 400, 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, 415, 416, 417, 418, 422, 428, 429, 431, 451, 500, 501, 502, 503, 504, 505, 511, 520, 522, 524, ]);the result:
It means that
That is, we need to check it exactly as:
if the |

Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.

Fixes #106
I think
onreadystatechangeis more than enough for our case. Otherwise, full support requires both XDomainRequest and XMLHttpRequest <_<