-
Notifications
You must be signed in to change notification settings - Fork 252
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
fix: inline origin resolution, drop original
dependency
#281
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
var original = require('original') | ||
var parse = require('url').parse | ||
var events = require('events') | ||
var https = require('https') | ||
|
@@ -157,8 +156,8 @@ function EventSource (url, eventSourceInitDict) { | |
_emit('error', new Event('error', {status: res.statusCode, message: res.statusMessage})) | ||
return | ||
} | ||
var prevOrigin = original(url) | ||
var nextOrigin = original(location) | ||
var prevOrigin = getOrigin(url) | ||
var nextOrigin = getOrigin(location) | ||
hasNewOrigin = prevOrigin !== nextOrigin | ||
if (res.statusCode === 307) reconnectUrl = url | ||
url = location | ||
|
@@ -280,7 +279,7 @@ function EventSource (url, eventSourceInitDict) { | |
_emit(type, new MessageEvent(type, { | ||
data: data.slice(0, -1), // remove trailing newline | ||
lastEventId: lastEventId, | ||
origin: original(url) | ||
origin: getOrigin(url) | ||
})) | ||
data = '' | ||
} | ||
|
@@ -471,3 +470,16 @@ function removeUnsafeHeaders (headers) { | |
|
||
return safe | ||
} | ||
|
||
/** | ||
* Transform an URL to a valid origin value. | ||
* | ||
* @param {String|Object} url URL to transform to it's origin. | ||
* @returns {String} The origin. | ||
* @api private | ||
*/ | ||
function getOrigin (url) { | ||
if (typeof url === 'string') url = parse(url) | ||
if (!url.protocol || !url.hostname) return 'null' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMO There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is confusing, but it is also in accordance with RFC6464, so I think I will leave it like this. |
||
return (url.protocol + '//' + url.host).toLowerCase() | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should leave
@link https://github.com/unshiftio/original/blob/507b362269c0ad4405d095aedc227c40aecaf68a/index.js
as credit to orignal code.