diff --git a/example/eventsource-polyfill.js b/example/eventsource-polyfill.js index 865f4ee..1295a38 100644 --- a/example/eventsource-polyfill.js +++ b/example/eventsource-polyfill.js @@ -3764,7 +3764,7 @@ var IncomingMessage = exports.IncomingMessage = function (xhr, response, mode, f self.url = response.url self.statusCode = response.status self.statusMessage = response.statusText - + response.headers.forEach(function (header, key){ self.headers[key.toLowerCase()] = header self.rawHeaders.push(key, header) @@ -3894,7 +3894,7 @@ IncomingMessage.prototype._onXHRProgress = function () { self.push(new Buffer(response)) break } - // Falls through in IE8 + // Falls through in IE8 case 'text': try { // This will fail when readyState = 3 in IE9. Switch mode and wait for readyState = 4 response = xhr.responseText @@ -6457,7 +6457,7 @@ function EventSource (url, eventSourceInitDict) { } // Handle HTTP redirects - if (res.statusCode === 301 || res.statusCode === 307) { + if (res.statusCode === 301 || res.statusCode === 302 || res.statusCode === 307) { if (!res.headers.location) { // Server sent redirect response without Location header. _emit('error', new Event('error', {status: res.statusCode})) @@ -10085,4 +10085,4 @@ if (typeof Object.create === 'function') { /***/ }) -/******/ ]); \ No newline at end of file +/******/ ]); diff --git a/lib/eventsource.js b/lib/eventsource.js index a7bb478..ca31229 100644 --- a/lib/eventsource.js +++ b/lib/eventsource.js @@ -139,7 +139,7 @@ function EventSource (url, eventSourceInitDict) { } // Handle HTTP redirects - if (res.statusCode === 301 || res.statusCode === 307) { + if (res.statusCode === 301 || res.statusCode === 302 || res.statusCode === 307) { if (!res.headers.location) { // Server sent redirect response without Location header. _emit('error', new Event('error', {status: res.statusCode, message: res.statusMessage})) diff --git a/test/eventsource_test.js b/test/eventsource_test.js index a547b32..4d79681 100644 --- a/test/eventsource_test.js +++ b/test/eventsource_test.js @@ -529,7 +529,7 @@ describe('HTTP Request', function () { }) }); - [301, 307].forEach(function (status) { + [301, 302, 307].forEach(function (status) { it('follows http ' + status + ' redirect', function (done) { var redirectSuffix = '/foobar' var clientRequestedRedirectUrl = false