Skip to content

Commit

Permalink
Support HTTP 302 redirects (#116)
Browse files Browse the repository at this point in the history
* Support HTTP 302 redirects

* added 302 to test and polyfill
  • Loading branch information
rybon authored and rexxars committed Jan 25, 2020
1 parent 7a4627a commit fe907fd
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions example/eventsource-polyfill.js
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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}))
Expand Down Expand Up @@ -10085,4 +10085,4 @@ if (typeof Object.create === 'function') {


/***/ })
/******/ ]);
/******/ ]);
2 changes: 1 addition & 1 deletion lib/eventsource.js
Expand Up @@ -142,7 +142,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}))
Expand Down
2 changes: 1 addition & 1 deletion test/eventsource_test.js
Expand Up @@ -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
Expand Down

0 comments on commit fe907fd

Please sign in to comment.