Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
some more try/catches around readyStates 2 and 3, now works properly …
…in opera
- Loading branch information
James Halliday
committed
Aug 20, 2011
1 parent
419cf54
commit 2a6fba6
Showing
7 changed files
with
75 additions
and
38 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<html> | ||
<head> | ||
<title>xhr</title> | ||
<script type="text/javascript" src="/browserify.js"></script> | ||
</head> | ||
<body> | ||
</body> | ||
</html> |
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
var EventEmitter = require('events').EventEmitter; | ||
|
||
var Response = module.exports = function (res) { | ||
this.offset = 0; | ||
}; | ||
|
||
Response.prototype = new EventEmitter; | ||
|
||
var capable = { | ||
streaming : true, | ||
status2 : true | ||
}; | ||
|
||
Response.prototype.handle = function (res) { | ||
if (res.readyState === 2 && capable.status2) { | ||
try { | ||
this.statusCode = res.status; | ||
} | ||
catch (err) { | ||
capable.status2 = false; | ||
} | ||
|
||
if (capable.status2) { | ||
this.emit('ready'); | ||
} | ||
} | ||
else if (capable.streaming && res.readyState === 3) { | ||
try { | ||
if (!this.statusCode) { | ||
this.statusCode = res.status; | ||
this.emit('ready'); | ||
} | ||
} | ||
catch (err) {} | ||
|
||
try { | ||
this.write(res); | ||
} | ||
catch (err) { | ||
capable.streaming = false; | ||
} | ||
} | ||
else if (res.readyState === 4) { | ||
if (!this.statusCode) { | ||
this.statusCode = res.status; | ||
this.emit('ready'); | ||
} | ||
this.write(res); | ||
|
||
if (res.error) { | ||
this.emit('error', res.responseText); | ||
} | ||
else this.emit('end'); | ||
} | ||
}; | ||
|
||
Response.prototype.write = function (res) { | ||
if (res.responseText.length > this.offset) { | ||
this.emit('data', res.responseText.slice(this.offset)); | ||
this.offset = res.responseText.length; | ||
} | ||
}; |
This file was deleted.
Oops, something went wrong.