ERR_HTTP2_CONNECT_SCHEME
Node.jsERRORNotableHTTP/2HIGH confidence
HTTP/2 CONNECT request must not include :scheme pseudo-header
Production Risk
Low — only affects HTTP/2 tunnelling code.
What this means
Thrown when an HTTP/2 CONNECT request includes the :scheme pseudo-header. RFC 7540 forbids :scheme in CONNECT requests; the scheme is implicit from the tunnel target in :authority.
Why it happens
- 1Including :scheme in a CONNECT request
- 2Generic request-building code that always adds :scheme
How to reproduce
Triggered when :scheme is present in an HTTP/2 CONNECT request.
trigger — this will error
trigger — this will error
const req = client.request({
':method': 'CONNECT',
':authority': 'target.example.com:443',
':scheme': 'https', // forbidden
});expected output
Error [ERR_HTTP2_CONNECT_SCHEME]: The :scheme header is forbidden for CONNECT requests
Fix
Remove :scheme from CONNECT requests
WHEN When constructing HTTP/2 CONNECT requests
Remove :scheme from CONNECT requests
const req = client.request({
':method': 'CONNECT',
':authority': 'target.example.com:443',
});Why this works
Omitting :scheme satisfies the RFC 7540 CONNECT constraint.
Code examples
Triggerjs
const req = client.request({
':method': 'CONNECT',
':authority': 'target.example.com:443',
':scheme': 'https', // forbidden
}); // this triggers ERR_HTTP2_CONNECT_SCHEMEHandle in try/catchjs
try {
// operation that may throw ERR_HTTP2_CONNECT_SCHEME
riskyOperation()
} catch (err) {
if (err.code === 'ERR_HTTP2_CONNECT_SCHEME') {
console.error('ERR_HTTP2_CONNECT_SCHEME:', err.message)
} else {
throw err
}
}Defensive pattern to avoid itjs
// Validate inputs before calling the operation
function safe_err_http2_connect_scheme(...args) {
// validate args here
return performOperation(...args)
}What not to do
✕ Use the same header template for CONNECT and regular requests
:scheme is forbidden in CONNECT and must be stripped.
Same error in other languages
Sources
Official documentation ↗
Node.js Error Codes Documentation
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev