mirror of
https://github.com/denoland/deno.git
synced 2025-02-01 12:16:11 -05:00
fix: use proper ALPN protocols if HTTP client is HTTP/1.1 only (#19303)
Closes https://github.com/denoland/deno/issues/16923 --------- Co-authored-by: crowlkats <crowlkats@toaxl.com> Co-authored-by: Matt Mastracci <matthew@mastracci.com>
This commit is contained in:
parent
fc6ba92024
commit
d90a75c036
6 changed files with 81 additions and 4 deletions
|
@ -151,7 +151,8 @@
|
||||||
"test-dns-promises-resolve.js",
|
"test-dns-promises-resolve.js",
|
||||||
"test-dns-regress-6244.js",
|
"test-dns-regress-6244.js",
|
||||||
"test-dns-setserver-in-callback-of-resolve4.js",
|
"test-dns-setserver-in-callback-of-resolve4.js",
|
||||||
"test-dns.js"
|
"test-dns.js",
|
||||||
|
"test-http-https-default-ports.js"
|
||||||
],
|
],
|
||||||
"parallel": [
|
"parallel": [
|
||||||
"test-assert-async.js",
|
"test-assert-async.js",
|
||||||
|
|
|
@ -0,0 +1,46 @@
|
||||||
|
// deno-fmt-ignore-file
|
||||||
|
// deno-lint-ignore-file
|
||||||
|
|
||||||
|
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
|
||||||
|
// Taken from Node 18.12.1
|
||||||
|
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
|
||||||
|
|
||||||
|
// Copyright Joyent, Inc. and other Node contributors.
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
|
// copy of this software and associated documentation files (the
|
||||||
|
// "Software"), to deal in the Software without restriction, including
|
||||||
|
// without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
// distribute, sublicense, and/or sell copies of the Software, and to permit
|
||||||
|
// persons to whom the Software is furnished to do so, subject to the
|
||||||
|
// following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included
|
||||||
|
// in all copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||||
|
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
||||||
|
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||||
|
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||||
|
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
||||||
|
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
|
'use strict';
|
||||||
|
const common = require('../common');
|
||||||
|
const { addresses } = require('../common/internet');
|
||||||
|
|
||||||
|
if (!common.hasCrypto)
|
||||||
|
common.skip('missing crypto');
|
||||||
|
|
||||||
|
const https = require('https');
|
||||||
|
|
||||||
|
const http = require('http');
|
||||||
|
|
||||||
|
https.get(`https://${addresses.INET_HOST}/`, common.mustCall((res) => {
|
||||||
|
res.resume();
|
||||||
|
}));
|
||||||
|
|
||||||
|
http.get(`http://${addresses.INET_HOST}/`, common.mustCall((res) => {
|
||||||
|
res.resume();
|
||||||
|
}));
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
import EventEmitter from "node:events";
|
import EventEmitter from "node:events";
|
||||||
import http, { type RequestOptions } from "node:http";
|
import http, { type RequestOptions } from "node:http";
|
||||||
|
import https from "node:https";
|
||||||
import {
|
import {
|
||||||
assert,
|
assert,
|
||||||
assertEquals,
|
assertEquals,
|
||||||
|
@ -509,3 +510,24 @@ Deno.test("[node/http] ClientRequest handle non-string headers", async () => {
|
||||||
await def;
|
await def;
|
||||||
assertEquals(headers!["1"], "2");
|
assertEquals(headers!["1"], "2");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Deno.test("[node/http] ClientRequest uses HTTP/1.1", async () => {
|
||||||
|
let body = "";
|
||||||
|
const def = deferred();
|
||||||
|
const req = https.request("https://localhost:5545/http_version", {
|
||||||
|
method: "POST",
|
||||||
|
headers: { 1: 2 },
|
||||||
|
}, (resp) => {
|
||||||
|
resp.on("data", (chunk) => {
|
||||||
|
body += chunk;
|
||||||
|
});
|
||||||
|
|
||||||
|
resp.on("end", () => {
|
||||||
|
def.resolve();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
req.once("error", (e) => def.reject(e));
|
||||||
|
req.end();
|
||||||
|
await def;
|
||||||
|
assertEquals(body, "HTTP/1.1");
|
||||||
|
});
|
||||||
|
|
|
@ -745,7 +745,14 @@ pub fn create_http_client(
|
||||||
options.client_cert_chain_and_key,
|
options.client_cert_chain_and_key,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
tls_config.alpn_protocols = vec!["h2".into(), "http/1.1".into()];
|
let mut alpn_protocols = vec![];
|
||||||
|
if options.http2 {
|
||||||
|
alpn_protocols.push("h2".into());
|
||||||
|
}
|
||||||
|
if options.http1 {
|
||||||
|
alpn_protocols.push("http/1.1".into());
|
||||||
|
}
|
||||||
|
tls_config.alpn_protocols = alpn_protocols;
|
||||||
|
|
||||||
let mut headers = HeaderMap::new();
|
let mut headers = HeaderMap::new();
|
||||||
headers.insert(USER_AGENT, user_agent.parse().unwrap());
|
headers.insert(USER_AGENT, user_agent.parse().unwrap());
|
||||||
|
|
|
@ -641,6 +641,8 @@ class ClientRequest extends OutgoingMessage {
|
||||||
}
|
}
|
||||||
this._client.close();
|
this._client.close();
|
||||||
const incoming = new IncomingMessageForClient(this.socket);
|
const incoming = new IncomingMessageForClient(this.socket);
|
||||||
|
incoming.req = this;
|
||||||
|
this.res = incoming;
|
||||||
|
|
||||||
// TODO(@crowlKats):
|
// TODO(@crowlKats):
|
||||||
// incoming.httpVersionMajor = versionMajor;
|
// incoming.httpVersionMajor = versionMajor;
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
NOTE: This file should not be manually edited. Please edit 'cli/tests/node_compat/config.json' and run 'tools/node_compat/setup.ts' instead.
|
NOTE: This file should not be manually edited. Please edit 'cli/tests/node_compat/config.json' and run 'tools/node_compat/setup.ts' instead.
|
||||||
|
|
||||||
Total: 2935
|
Total: 2934
|
||||||
|
|
||||||
- [abort/test-abort-backtrace.js](https://github.com/nodejs/node/tree/v18.12.1/test/abort/test-abort-backtrace.js)
|
- [abort/test-abort-backtrace.js](https://github.com/nodejs/node/tree/v18.12.1/test/abort/test-abort-backtrace.js)
|
||||||
- [abort/test-abort-fatal-error.js](https://github.com/nodejs/node/tree/v18.12.1/test/abort/test-abort-fatal-error.js)
|
- [abort/test-abort-fatal-error.js](https://github.com/nodejs/node/tree/v18.12.1/test/abort/test-abort-fatal-error.js)
|
||||||
|
@ -88,7 +88,6 @@ Total: 2935
|
||||||
- [internet/test-dns-cares-domains.js](https://github.com/nodejs/node/tree/v18.12.1/test/internet/test-dns-cares-domains.js)
|
- [internet/test-dns-cares-domains.js](https://github.com/nodejs/node/tree/v18.12.1/test/internet/test-dns-cares-domains.js)
|
||||||
- [internet/test-dns-txt-sigsegv.js](https://github.com/nodejs/node/tree/v18.12.1/test/internet/test-dns-txt-sigsegv.js)
|
- [internet/test-dns-txt-sigsegv.js](https://github.com/nodejs/node/tree/v18.12.1/test/internet/test-dns-txt-sigsegv.js)
|
||||||
- [internet/test-http-dns-fail.js](https://github.com/nodejs/node/tree/v18.12.1/test/internet/test-http-dns-fail.js)
|
- [internet/test-http-dns-fail.js](https://github.com/nodejs/node/tree/v18.12.1/test/internet/test-http-dns-fail.js)
|
||||||
- [internet/test-http-https-default-ports.js](https://github.com/nodejs/node/tree/v18.12.1/test/internet/test-http-https-default-ports.js)
|
|
||||||
- [internet/test-http2-issue-32922.js](https://github.com/nodejs/node/tree/v18.12.1/test/internet/test-http2-issue-32922.js)
|
- [internet/test-http2-issue-32922.js](https://github.com/nodejs/node/tree/v18.12.1/test/internet/test-http2-issue-32922.js)
|
||||||
- [internet/test-https-issue-43963.js](https://github.com/nodejs/node/tree/v18.12.1/test/internet/test-https-issue-43963.js)
|
- [internet/test-https-issue-43963.js](https://github.com/nodejs/node/tree/v18.12.1/test/internet/test-https-issue-43963.js)
|
||||||
- [internet/test-inspector-help-page.js](https://github.com/nodejs/node/tree/v18.12.1/test/internet/test-inspector-help-page.js)
|
- [internet/test-inspector-help-page.js](https://github.com/nodejs/node/tree/v18.12.1/test/internet/test-inspector-help-page.js)
|
||||||
|
|
Loading…
Add table
Reference in a new issue