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

feat: allow connection header in request #1747

Closed
wants to merge 1 commit into from
Closed
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
6 changes: 5 additions & 1 deletion lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -1295,7 +1295,7 @@ function _resume (client, sync) {
}

function write (client, request) {
const { body, method, path, host, upgrade, headers, blocking } = request
const { body, method, path, host, upgrade, headers, blocking, reset } = request

// https://tools.ietf.org/html/rfc7231#section-4.3.1
// https://tools.ietf.org/html/rfc7231#section-4.3.2
Expand Down Expand Up @@ -1381,6 +1381,10 @@ function write (client, request) {
socket[kReset] = true
}

if (reset) {
socket[kReset] = true
}

if (blocking) {
socket[kBlocking] = true
}
Expand Down
9 changes: 8 additions & 1 deletion lib/core/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class Request {
upgrade,
headersTimeout,
bodyTimeout,
reset,
throwOnError
}, handler) {
if (typeof path !== 'string') {
Expand Down Expand Up @@ -105,6 +106,8 @@ class Request {

this.method = method

this.reset = reset

if (body == null) {
this.body = null
} else if (util.isStream(body)) {
Expand Down Expand Up @@ -311,7 +314,11 @@ function processHeader (request, key, val) {
key.length === 10 &&
key.toLowerCase() === 'connection'
) {
throw new InvalidArgumentError('invalid connection header')
if (val.toLowerCase() === 'close') {
this.reset = true
} else if (val.toLowerCase() !== 'keep-alive') {
throw new InvalidArgumentError('invalid connection header')
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if there is a conflict between header and reset option?

Copy link
Member

@metcoder95 metcoder95 Dec 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should reset be always taking the prevalence?

}
} else if (
key.length === 10 &&
key.toLowerCase() === 'keep-alive'
Expand Down