-
Notifications
You must be signed in to change notification settings - Fork 30.6k
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
http2: initial support for originSet #17935
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,7 +70,9 @@ const TLSServer = tls.Server; | |
|
||
const kInspect = require('internal/util').customInspectSymbol; | ||
|
||
const kAlpnProtocol = Symbol('alpnProtocol'); | ||
const kAuthority = Symbol('authority'); | ||
const kEncrypted = Symbol('encrypted'); | ||
const kHandle = Symbol('handle'); | ||
const kID = Symbol('id'); | ||
const kInit = Symbol('init'); | ||
|
@@ -731,6 +733,17 @@ function setupHandle(socket, type, options) { | |
|
||
this[kHandle] = handle; | ||
|
||
if (socket.encrypted) { | ||
this[kAlpnProtocol] = socket.alpnProtocol; | ||
this[kEncrypted] = true; | ||
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. Should we define these on the initial |
||
} else { | ||
// 'h2c' is the protocol identifier for HTTP/2 over plain-text. We use | ||
// it here to identify any session that is not explicitly using an | ||
// encrypted socket. | ||
this[kAlpnProtocol] = 'h2c'; | ||
this[kEncrypted] = false; | ||
} | ||
|
||
const settings = typeof options.settings === 'object' ? | ||
options.settings : {}; | ||
|
||
|
@@ -805,9 +818,12 @@ class Http2Session extends EventEmitter { | |
streams: new Map(), | ||
pendingStreams: new Set(), | ||
pendingAck: 0, | ||
writeQueueSize: 0 | ||
writeQueueSize: 0, | ||
originSet: undefined | ||
}; | ||
|
||
this[kEncrypted] = undefined; | ||
this[kAlpnProtocol] = undefined; | ||
this[kType] = type; | ||
this[kProxySocket] = null; | ||
this[kSocket] = socket; | ||
|
@@ -833,6 +849,46 @@ class Http2Session extends EventEmitter { | |
debug(`Http2Session ${sessionName(type)}: created`); | ||
} | ||
|
||
// Returns undefined if the socket is not yet connected, true if the | ||
// socket is a TLSSocket, and false if it is not. | ||
get encrypted() { | ||
return this[kEncrypted]; | ||
} | ||
|
||
// Returns undefined if the socket is not yet connected, `h2` if the | ||
// socket is a TLSSocket and the alpnProtocol is `h2`, or `h2c` if the | ||
// socket is not a TLSSocket. | ||
get alpnProtocol() { | ||
return this[kAlpnProtocol]; | ||
} | ||
|
||
// TODO(jasnell): originSet is being added in preparation for ORIGIN frame | ||
// support. At the current time, the ORIGIN frame specification is awaiting | ||
// publication as an RFC and is awaiting implementation in nghttp2. Once | ||
// added, an ORIGIN frame will add to the origins included in the origin | ||
// set. 421 responses will remove origins from the set. | ||
get originSet() { | ||
if (!this.encrypted || this.destroyed) | ||
return undefined; | ||
|
||
let originSet = this[kState].originSet; | ||
if (originSet === undefined) { | ||
const socket = this[kSocket]; | ||
this[kState].originSet = originSet = new Set(); | ||
if (socket.servername != null) { | ||
let originString = `https://${socket.servername}`; | ||
if (socket.remotePort != null) | ||
originString += `:${socket.remotePort}`; | ||
// We have to ensure that it is a properly serialized | ||
// ASCII origin string. The socket.servername might not | ||
// be properly ASCII encoded. | ||
originSet.add((new URL(originString)).origin); | ||
} | ||
} | ||
|
||
return Array.from(originSet); | ||
} | ||
|
||
// True if the Http2Session is still waiting for the socket to connect | ||
get connecting() { | ||
return (this[kState].flags & SESSION_FLAGS_READY) === 0; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
There should be a type annotation here, like
* {string|undefined}
Ditto below.