Bug 1708567 - Add support for HTTP3 version 1 behind a pref r=necko-reviewers,valentin

Differential Revision: https://phabricator.services.mozilla.com/D113881
This commit is contained in:
Dragana Damjanovic 2021-04-30 11:33:39 +00:00
Родитель 40ba1969ba
Коммит fe31a10105
10 изменённых файлов: 121 добавлений и 10 удалений

Просмотреть файл

@ -9533,6 +9533,12 @@
value: @IS_EARLY_BETA_OR_EARLIER@
mirror: always
# Support http3 version1
- name: network.http.http3.support_version1
type: RelaxedAtomicBool
value: false
mirror: always
#---------------------------------------------------------------------------
# Prefs starting with "nglayout."
#---------------------------------------------------------------------------

Просмотреть файл

@ -28,9 +28,10 @@
namespace mozilla {
namespace net {
const uint32_t kHttp3VersionCount = 6;
const uint32_t kHttp3VersionCount = 7;
const nsCString kHttp3Versions[] = {"h3-27"_ns, "h3-28"_ns, "h3-29"_ns,
"h3-30"_ns, "h3-31"_ns, "h3-32"_ns};
"h3-30"_ns, "h3-31"_ns, "h3-32"_ns,
"h3"_ns};
// define storage for all atoms
namespace nsHttp {

Просмотреть файл

@ -2710,6 +2710,10 @@ HttpTrafficAnalyzer* nsHttpHandler::GetHttpTrafficAnalyzer() {
}
bool nsHttpHandler::IsHttp3VersionSupported(const nsACString& version) {
if (!StaticPrefs::network_http_http3_support_version1() &&
version.EqualsLiteral("h3")) {
return false;
}
for (uint32_t i = 0; i < kHttp3VersionCount; i++) {
if (version.Equals(kHttp3Versions[i])) {
return true;

Просмотреть файл

@ -83,6 +83,7 @@ impl NeqoHttp3Conn {
"h3-29" => QuicVersion::Draft29,
"h3-28" => QuicVersion::Draft28,
"h3-27" => QuicVersion::Draft27,
"h3" => QuicVersion::Version1,
_ => return Err(NS_ERROR_INVALID_ARG),
};

Просмотреть файл

@ -33,7 +33,7 @@ use std::net::SocketAddr;
const MAX_TABLE_SIZE: u64 = 65536;
const MAX_BLOCKED_STREAMS: u16 = 10;
const PROTOCOLS: &[&str] = &["h3-27"];
const PROTOCOLS: &[&str] = &["h3-27", "h3"];
const TIMER_TOKEN: Token = Token(0xffff);
const HTTP_RESPONSE_WITH_WRONG_FRAME: &[u8] = &[

Просмотреть файл

@ -5,7 +5,7 @@
/* import-globals-from head_channels.js */
/* import-globals-from head_cookies.js */
async function http3_setup_tests() {
async function http3_setup_tests(http3version) {
let env = Cc["@mozilla.org/process/environment;1"].getService(
Ci.nsIEnvironment
);
@ -21,7 +21,7 @@ async function http3_setup_tests() {
Services.prefs.setBoolPref("network.dns.disableIPv6", true);
Services.prefs.setCharPref(
"network.http.http3.alt-svc-mapping-for-testing",
"foo.example.com;h3-27=:" + h3Port
`foo.example.com;${http3version}=:${h3Port}`
);
let certdb = Cc["@mozilla.org/security/x509certdb;1"].getService(
@ -29,7 +29,7 @@ async function http3_setup_tests() {
);
addCertFromFile(certdb, "http2-ca.pem", "CTu,u,u");
await setup_altsvc("https://foo.example.com/", h3Route);
await setup_altsvc("https://foo.example.com/", h3Route, http3version);
}
function makeChan(uri) {
@ -45,6 +45,7 @@ let CheckHttp3Listener = function() {};
CheckHttp3Listener.prototype = {
expectedRoute: "",
http3version: "",
onStartRequest: function testOnStartRequest(request) {},
@ -64,7 +65,7 @@ CheckHttp3Listener.prototype = {
try {
httpVersion = request.protocolVersion;
} catch (e) {}
Assert.equal(httpVersion, "h3-27");
Assert.equal(httpVersion, this.http3version);
this.finish(true);
} else {
dump("try again to get alt svc mapping\n");
@ -73,12 +74,13 @@ CheckHttp3Listener.prototype = {
},
};
async function setup_altsvc(uri, expectedRoute) {
async function setup_altsvc(uri, expectedRoute, http3version) {
let result = false;
do {
let chan = makeChan(uri);
let listener = new CheckHttp3Listener();
listener.expectedRoute = expectedRoute;
listener.http3version = http3version;
result = await altsvcSetupPromise(chan, listener);
dump("results=" + result);
} while (result === false);
@ -101,5 +103,6 @@ function http3_clear_prefs() {
Services.prefs.clearUserPref(
"network.http.http3.alt-svc-mapping-for-testing"
);
Services.prefs.clearUserPref("network.http.http3.support_version1");
dump("cleanup done\n");
}

Просмотреть файл

@ -7,7 +7,7 @@ registerCleanupFunction(async () => {
});
add_task(async function setup() {
await http3_setup_tests();
await http3_setup_tests("h3-27");
});
let Http3Listener = function() {};

Просмотреть файл

@ -7,7 +7,7 @@ registerCleanupFunction(async () => {
});
add_task(async function setup() {
await http3_setup_tests();
await http3_setup_tests("h3-27");
});
let Http3Listener = function() {};

Просмотреть файл

@ -0,0 +1,94 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
registerCleanupFunction(async () => {
http3_clear_prefs();
});
let httpsUri;
add_task(async function pre_setup() {
let env = Cc["@mozilla.org/process/environment;1"].getService(
Ci.nsIEnvironment
);
let h2Port = env.get("MOZHTTP2_PORT");
Assert.notEqual(h2Port, null);
Assert.notEqual(h2Port, "");
httpsUri = "https://foo.example.com:" + h2Port + "/";
Services.prefs.setBoolPref("network.http.http3.support_version1", true);
});
add_task(async function setup() {
await http3_setup_tests("h3");
});
function chanPromise(chan, listener) {
return new Promise(resolve => {
function finish() {
resolve();
}
listener.finish = finish;
chan.asyncOpen(listener);
});
}
function makeChan() {
let chan = NetUtil.newChannel({
uri: httpsUri,
loadUsingSystemPrincipal: true,
}).QueryInterface(Ci.nsIHttpChannel);
chan.loadFlags = Ci.nsIChannel.LOAD_INITIAL_DOCUMENT_URI;
return chan;
}
let Http3Listener = function() {};
Http3Listener.prototype = {
version1enabled: "",
onStartRequest: function testOnStartRequest(request) {},
onDataAvailable: function testOnDataAvailable(request, stream, off, cnt) {
read_stream(stream, cnt);
},
onStopRequest: function testOnStopRequest(request, status) {
let httpVersion = "";
try {
httpVersion = request.protocolVersion;
} catch (e) {}
if (this.version1enabled) {
Assert.equal(httpVersion, "h3");
} else {
Assert.equal(httpVersion, "h2");
}
this.finish();
},
};
add_task(async function test_version1_enabled_1() {
let listener = new Http3Listener();
listener.version1enabled = true;
let chan = makeChan("https://foo.example.com/");
await chanPromise(chan, listener);
});
add_task(async function test_version1_disabled() {
Services.prefs.setBoolPref("network.http.http3.support_version1", false);
let listener = new Http3Listener();
listener.version1enabled = false;
let chan = makeChan("https://foo.example.com/");
await chanPromise(chan, listener);
});
add_task(async function test_version1_enabled_2() {
Services.prefs.setBoolPref("network.http.http3.support_version1", true);
let listener = new Http3Listener();
listener.version1enabled = true;
let chan = makeChan("https://foo.example.com/");
await chanPromise(chan, listener);
});

Просмотреть файл

@ -514,5 +514,7 @@ skip-if = os =='android'
run-sequentially = node server exceptions dont replay well
[test_http_server_timing.js]
skip-if = os =='android'
[test_http3_version1.js]
skip-if = asan || tsan || os == 'win' || os =='android' || socketprocess_networking
[test_trr_domain.js]
skip-if = os =='android'