Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions lib/core/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -919,11 +919,32 @@ function onConnectTimeout (socket, opts) {
destroy(socket, new ConnectTimeoutError(message))
}

let lastUrlString = null
let lastProtocol = null

/**
* @param {string} urlString
* @returns {string}
*/
function getProtocolFromUrlString (urlString) {
// Requests are typically dispatched against the same origin over and over,
// so cache the last (urlString, protocol) pair to skip re-parsing.
if (urlString === lastUrlString) {
return lastProtocol
}

const protocol = getProtocolFromUrlStringSlow(urlString)
lastUrlString = urlString
lastProtocol = protocol

return protocol
}

/**
* @param {string} urlString
* @returns {string}
*/
function getProtocolFromUrlStringSlow (urlString) {
if (
urlString[0] === 'h' &&
urlString[1] === 't' &&
Expand Down
Loading
Loading