-
Notifications
You must be signed in to change notification settings - Fork 539
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
feat: allow connection header in request #1829
Changes from 18 commits
82da79d
f06b0a5
9113050
8e2673a
eea5735
fe68676
c79a6c2
412b9a8
8632fbc
0651207
0965f3d
4349c33
ed6fd0e
ae04e7d
d516952
e732ea0
9e78222
96d74fc
42914fe
b38df21
8208e9c
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 |
---|---|---|
|
@@ -54,19 +54,22 @@ try { | |
} | ||
|
||
class Request { | ||
constructor (origin, { | ||
path, | ||
method, | ||
body, | ||
headers, | ||
query, | ||
idempotent, | ||
blocking, | ||
upgrade, | ||
headersTimeout, | ||
bodyTimeout, | ||
throwOnError | ||
}, handler) { | ||
constructor (origin, options, handler) { | ||
const { | ||
path, | ||
method, | ||
body, | ||
headers, | ||
query, | ||
idempotent, | ||
blocking, | ||
upgrade, | ||
headersTimeout, | ||
bodyTimeout, | ||
reset, | ||
throwOnError | ||
} = options | ||
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. Why change this? 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. Do you mean the reset? Mostly to validate the Another option is to pass it as a third-parameter to the 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. Just add |
||
|
||
if (typeof path !== 'string') { | ||
throw new InvalidArgumentError('path must be a string') | ||
} else if ( | ||
|
@@ -97,6 +100,10 @@ class Request { | |
throw new InvalidArgumentError('invalid bodyTimeout') | ||
} | ||
|
||
if (reset != null && typeof reset !== 'boolean') { | ||
throw new InvalidArgumentError('invalid reset') | ||
} | ||
|
||
this.headersTimeout = headersTimeout | ||
|
||
this.bodyTimeout = bodyTimeout | ||
|
@@ -139,6 +146,8 @@ class Request { | |
|
||
this.blocking = blocking == null ? false : blocking | ||
|
||
this.reset = reset == null ? false : reset | ||
|
||
this.host = null | ||
|
||
this.contentLength = null | ||
|
@@ -250,6 +259,7 @@ class Request { | |
if (channels.trailers.hasSubscribers) { | ||
channels.trailers.publish({ request: this, trailers }) | ||
} | ||
|
||
ronag marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return this[kHandler].onComplete(trailers) | ||
} | ||
|
||
|
@@ -320,7 +330,10 @@ function processHeader (request, key, val) { | |
key.length === 10 && | ||
key.toLowerCase() === 'connection' | ||
) { | ||
throw new InvalidArgumentError('invalid connection header') | ||
if (val.toLowerCase() === 'close') { | ||
request.reset = true | ||
} | ||
request.headers += `${key}: ${val}\r\n` | ||
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. We should not set the header here... 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. Better to do it in 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. Instead, just switching the value on the 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. Just remove |
||
} else if ( | ||
key.length === 10 && | ||
key.toLowerCase() === 'keep-alive' | ||
|
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.
@metcoder95 This is phrased in a confusing way. Documentation implies that "true" means creating long-lived connection, while code seems to indicate the opposite.
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.
You're right, let me fix it opening a new PR, thanks for the heads up 🙇