diff --git a/src/http.zig b/src/http.zig index 9b9ccf7bd5..fb2631dc56 100644 --- a/src/http.zig +++ b/src/http.zig @@ -632,6 +632,8 @@ pub fn buildRequest(this: *HTTPClient, body_len: usize) picohttp.Request { const connection_value = this.headerStr(header_values[i]); if (std.ascii.eqlIgnoreCase(connection_value, "close")) { this.flags.disable_keepalive = true; + } else if (std.ascii.eqlIgnoreCase(connection_value, "keep-alive")) { + this.flags.disable_keepalive = false; } }, hashHeaderConst("if-modified-since") => { @@ -2279,8 +2281,11 @@ pub fn handleResponseMetadata( }, hashHeaderConst("Connection") => { if (response.status_code >= 200 and response.status_code <= 299) { - if (!strings.eqlComptime(header.value, "keep-alive")) { + // HTTP headers are case-insensitive (RFC 7230) + if (std.ascii.eqlIgnoreCase(header.value, "close")) { this.state.flags.allow_keepalive = false; + } else if (std.ascii.eqlIgnoreCase(header.value, "keep-alive")) { + this.state.flags.allow_keepalive = true; } } }, diff --git a/src/js/node/_http_client.ts b/src/js/node/_http_client.ts index f01d4f4629..6e0ced4dda 100644 --- a/src/js/node/_http_client.ts +++ b/src/js/node/_http_client.ts @@ -268,7 +268,7 @@ function ClientRequest(input, options, cb) { const method = this[kMethod]; let keepalive = true; - const agentKeepalive = this[kAgent]?.keepalive; + const agentKeepalive = this[kAgent]?.keepAlive; if (agentKeepalive !== undefined) { keepalive = agentKeepalive; }