Skip to content

Commit fe907fd

Browse files
rybonrexxars
authored andcommitted
Support HTTP 302 redirects (#116)
* Support HTTP 302 redirects * added 302 to test and polyfill
1 parent 7a4627a commit fe907fd

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

example/eventsource-polyfill.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3764,7 +3764,7 @@ var IncomingMessage = exports.IncomingMessage = function (xhr, response, mode, f
37643764
self.url = response.url
37653765
self.statusCode = response.status
37663766
self.statusMessage = response.statusText
3767-
3767+
37683768
response.headers.forEach(function (header, key){
37693769
self.headers[key.toLowerCase()] = header
37703770
self.rawHeaders.push(key, header)
@@ -3894,7 +3894,7 @@ IncomingMessage.prototype._onXHRProgress = function () {
38943894
self.push(new Buffer(response))
38953895
break
38963896
}
3897-
// Falls through in IE8
3897+
// Falls through in IE8
38983898
case 'text':
38993899
try { // This will fail when readyState = 3 in IE9. Switch mode and wait for readyState = 4
39003900
response = xhr.responseText
@@ -6457,7 +6457,7 @@ function EventSource (url, eventSourceInitDict) {
64576457
}
64586458

64596459
// Handle HTTP redirects
6460-
if (res.statusCode === 301 || res.statusCode === 307) {
6460+
if (res.statusCode === 301 || res.statusCode === 302 || res.statusCode === 307) {
64616461
if (!res.headers.location) {
64626462
// Server sent redirect response without Location header.
64636463
_emit('error', new Event('error', {status: res.statusCode}))
@@ -10085,4 +10085,4 @@ if (typeof Object.create === 'function') {
1008510085

1008610086

1008710087
/***/ })
10088-
/******/ ]);
10088+
/******/ ]);

lib/eventsource.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ function EventSource (url, eventSourceInitDict) {
142142
}
143143

144144
// Handle HTTP redirects
145-
if (res.statusCode === 301 || res.statusCode === 307) {
145+
if (res.statusCode === 301 || res.statusCode === 302 || res.statusCode === 307) {
146146
if (!res.headers.location) {
147147
// Server sent redirect response without Location header.
148148
_emit('error', new Event('error', {status: res.statusCode, message: res.statusMessage}))

test/eventsource_test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ describe('HTTP Request', function () {
529529
})
530530
});
531531

532-
[301, 307].forEach(function (status) {
532+
[301, 302, 307].forEach(function (status) {
533533
it('follows http ' + status + ' redirect', function (done) {
534534
var redirectSuffix = '/foobar'
535535
var clientRequestedRedirectUrl = false

0 commit comments

Comments
 (0)