-
-
Save rwaldron/599431 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php header('HTTP/1.0 500 Internal Server Error'); exit; ?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- | |
There is no way, in Opera, to figure out if an incoming page | |
is returning a 304 status. | |
Opera provides no indicator as to if a 304 occurred. | |
- xhr.status === 0 | |
- xhr.statusText === "" | |
- xhr.getAllResponseHeader() === "" | |
- xhr.getResponseHeader( anything ) (not found) | |
All of the above is virtually identical to an aborted request in other browsers. | |
Example here: http://ejohn.org/files/bugs/304/ | |
--> | |
<ul id="out"></ul> | |
<script> | |
window.onload = function() { | |
request("success.php", 200); | |
request("error.php", 500); | |
request("404.php", 404); | |
request("not_modified.php", 304); | |
request("wait.php", 0); | |
}; | |
function request(url, expect) { | |
var xhr = window.XMLHttpRequest ? new window.XMLHttpRequest() : new window.ActiveXObject("Microsoft.XMLHTTP"); | |
xhr.open( "GET", url, true ); | |
var onreadystatechange = xhr.onreadystatechange = function() { | |
// If readyState === 0 then abort occurred, according to Opera | |
if ( xhr.readyState === 4 || xhr.readyState === 0 ) { | |
// Opera gives status of 0 for 500 errors | |
// Unfortunately this leads to ambiguity between errors and 304/Not Modified | |
// As not modified pages ALSO return a status of 0 | |
if ( xhr.status === expect ) { | |
log( "PASS: " + url ); | |
} else { | |
log( "FAIL: " + url + " (" + xhr.status + ")" ); | |
} | |
xhr.onreadystatechange = null; | |
} | |
}; | |
xhr.send( null ); | |
if ( /wait/.test( url ) ) { | |
setTimeout(function(){ | |
xhr.abort(); | |
// Opera doesn't fire onreadystatechange on abort, fire it explicitly | |
if ( xhr.onreadystatechange ) { | |
onreadystatechange(); | |
} | |
}, 13); | |
} | |
} | |
function log( msg ) { | |
document.getElementById("out").innerHTML += "<li>" + msg + "</li>"; | |
} | |
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php header('HTTP/1.0 304 Not Modified'); exit; ?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
yay |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php sleep(10); exit; ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment