Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support HTTP 302 redirects #116

Merged
merged 2 commits into from Jan 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -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}))
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