Commit 42aa3f6

Browse files
jasnelladuh95
authored andcommitted
quic: add applicationOptions to session
Signed-off-by: James M Snell <jasnell@gmail.com> PR-URL: #63267 Backport-PR-URL: #64675 Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
1 parent 4c00ab9 commit 42aa3f6

11 files changed

Lines changed: 320 additions & 71 deletions

File tree

‎doc/api/quic.md‎

Lines changed: 78 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,18 @@ added: v23.8.0
724724

725725
A `QuicSession` represents the local side of a QUIC connection.
726726

727+
### `session.applicationOptions`
728+
729+
<!-- YAML
730+
added: REPLACEME
731+
-->
732+
733+
* Type: {quic.ApplicationOptions}
734+
735+
The current application-level options for this session. These include settings
736+
that are specific to the negotiated application protocol (e.g. HTTP/3) and may
737+
be negotiated separately from the transport parameters. Read only.
738+
727739
### `session.close([options])`
728740

729741
<!-- YAML
@@ -2218,6 +2230,70 @@ added: v23.8.0
22182230

22192231
## Types
22202232

2233+
### type: `ApplicationOptions`
2234+
2235+
<!-- YAML
2236+
added: REPLACEME
2237+
-->
2238+
2239+
* Type: {Object}
2240+
2241+
The application specific options.
2242+
2243+
#### `applicationOptions.maxHeaderPairs`
2244+
2245+
* Type: {bigint|number}
2246+
2247+
Maximum number of header name-value pairs accepted per header block.
2248+
Headers beyond this limit are silently dropped. **Default:**`128`
2249+
2250+
#### `applicationOptions.maxHeaderLength`
2251+
2252+
* Type: {bigint|number}
2253+
2254+
Maximum total byte length of all header names and values combined per header
2255+
block. Headers that would push the total over this limit are silently
2256+
dropped. **Default:**`8192`
2257+
2258+
#### `applicationOptions.maxFieldSectionSize`
2259+
2260+
* Type: {bigint|number}
2261+
2262+
Maximum size of a compressed header field section (QPACK). `0` means
2263+
unlimited. **Default:**`0`
2264+
2265+
#### `applicationOptions.qpackMaxDTableCapacity`
2266+
2267+
* Type: {bigint|number}
2268+
2269+
QPACK dynamic table capacity in bytes. Set to `0` to disable the dynamic
2270+
table. **Default:**`4096`
2271+
2272+
#### `applicationOptions.qpackEncoderMaxDTableCapacity`
2273+
2274+
* Type: {bigint|number}
2275+
2276+
QPACK encoder maximum dynamic table capacity. **Default:**`4096`
2277+
2278+
#### `applicationOptions.qpackBlockedStreams`
2279+
2280+
* Type: {bigint|number}
2281+
2282+
Maximum number of streams that can e blocked waiting for QPACK dynamic table
2283+
updates. **Default:**`100`
2284+
2285+
#### `applicationOptions.enableConnectProtocol`
2286+
2287+
* Type: {boolean}
2288+
2289+
Enable the extended CONNECT protocol (RFC 9220). **Default:**`false`
2290+
2291+
#### `applicationOptions.enableDatagrams`
2292+
2293+
* Type: {boolean}
2294+
2295+
Enable HTTP/3 datagrams (RFC 9297). **Default:**`false`
2296+
22212297
### Type: `EndpointOptions`
22222298

22232299
<!-- YAML
@@ -2474,30 +2550,9 @@ Default: `'h3'`
24742550
added: REPLACEME
24752551
-->
24762552

2477-
* Type: {Object}
2553+
* Type: {quic.ApplicationOptions}
24782554

2479-
HTTP/3 application-specific options. These only apply when the negotiated
2480-
ALPN selects the HTTP/3 application (`'h3'`).
2481-
2482-
*`maxHeaderPairs` {number} Maximum number of header name-value pairs
2483-
accepted per header block. Headers beyond this limit are silently
2484-
dropped. **Default:**`128`
2485-
*`maxHeaderLength` {number} Maximum total byte length of all header
2486-
names and values combined per header block. Headers that would push
2487-
the total over this limit are silently dropped. **Default:**`8192`
2488-
*`maxFieldSectionSize` {number} Maximum size of a compressed header
2489-
field section (QPACK). `0` means unlimited. **Default:**`0`
2490-
*`qpackMaxDTableCapacity` {number} QPACK dynamic table capacity in
2491-
bytes. Set to `0` to disable the dynamic table. **Default:**`4096`
2492-
*`qpackEncoderMaxDTableCapacity` {number} QPACK encoder maximum
2493-
dynamic table capacity. **Default:**`4096`
2494-
*`qpackBlockedStreams` {number} Maximum number of streams that can
2495-
be blocked waiting for QPACK dynamic table updates.
2496-
**Default:**`100`
2497-
*`enableConnectProtocol` {boolean} Enable the extended CONNECT
2498-
protocol (RFC 9220). **Default:**`false`
2499-
*`enableDatagrams` {boolean} Enable HTTP/3 datagrams (RFC 9297).
2500-
**Default:**`false`
2555+
Application-specific options.
25012556

25022557
```mjs
25032558
const { listen } =awaitimport('node:quic');

‎lib/internal/quic/quic.js‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2678,6 +2678,14 @@ class QuicSession {
26782678
debug('session created');
26792679
}
26802680

2681+
getapplicationOptions(){
2682+
// We don't cache application options because they may be updated by the
2683+
// C++ layer after session creation depending on the behavior of the
2684+
// application.
2685+
if(this.destroyed)returnnull;
2686+
returnthis.#handle.applicationOptions();
2687+
}
2688+
26812689
getlocalTransportParams(){
26822690
if(this.#inner.localTransportParams!==undefined){
26832691
returnthis.#inner.localTransportParams;

‎src/quic/application.cc‎

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,13 @@
1919

2020
namespacenode {
2121

22+
using v8::BigInt;
23+
using v8::Boolean;
24+
using v8::DictionaryTemplate;
2225
using v8::Just;
2326
using v8::Local;
2427
using v8::Maybe;
28+
using v8::MaybeLocal;
2529
using v8::Nothing;
2630
using v8::Object;
2731
using v8::Value;
@@ -114,6 +118,44 @@ Maybe<Session::Application_Options> Session::Application_Options::From(
114118
return Just<Application_Options>(options);
115119
}
116120

121+
MaybeLocal<Object> Session::Application_Options::ToObject(
122+
Environment* env) const {
123+
auto& binding_data = BindingData::Get(env);
124+
auto tmpl = binding_data.application_options_template();
125+
staticconstexpr std::string_view names[] = {
126+
"maxHeaderPairs",
127+
"maxHeaderLength",
128+
"maxFieldSectionSize",
129+
"qpackMaxDtableCapacity",
130+
"qpackEncoderMaxDtableCapacity",
131+
"qpackBlockedStreams",
132+
"enableConnectProtocol",
133+
"enableDatagrams",
134+
};
135+
if (tmpl.IsEmpty()) {
136+
tmpl = DictionaryTemplate::New(env->isolate(), names);
137+
binding_data.set_application_options_template(tmpl);
138+
}
139+
MaybeLocal<Value> values[] = {
140+
BigInt::NewFromUnsigned(env->isolate(), max_header_pairs),
141+
BigInt::NewFromUnsigned(env->isolate(), max_header_length),
142+
BigInt::NewFromUnsigned(env->isolate(), max_field_section_size),
143+
BigInt::NewFromUnsigned(env->isolate(), qpack_max_dtable_capacity),
144+
BigInt::NewFromUnsigned(env->isolate(),
145+
qpack_encoder_max_dtable_capacity),
146+
BigInt::NewFromUnsigned(env->isolate(), qpack_blocked_streams),
147+
Boolean::New(env->isolate(), enable_connect_protocol),
148+
Boolean::New(env->isolate(), enable_datagrams),
149+
};
150+
static_assert(std::size(values) == std::size(names));
151+
152+
auto obj = tmpl->NewInstance(env->context(), values);
153+
if (obj->SetPrototypeV2(env->context(), Null(env->isolate())).IsNothing()) {
154+
return {};
155+
}
156+
return obj;
157+
}
158+
117159
// ============================================================================
118160

119161
std::string Session::Application::StreamData::ToString() const {
@@ -655,7 +697,10 @@ class DefaultApplication final : public Session::Application {
655697
// Marked NOLINT because the cpp linter gets confused about this using
656698
// statement not being sorted with the using v8 statements at the top
657699
// of the namespace.
658-
using Application::Application; // NOLINT
700+
DefaultApplication(Session* session, const Options& options)
701+
: Session::Application(session, options), options_(options) {}
702+
703+
const Options& options() constoverride { return options_; }
659704

660705
Session::Application::Type type() constoverride {
661706
return Session::Application::Type::DEFAULT;
@@ -827,6 +872,8 @@ class DefaultApplication final : public Session::Application {
827872
}
828873
}
829874

875+
Options options_;
876+
830877
Stream::Queue stream_queue_;
831878
};
832879

‎src/quic/application.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ class Session::Application : public MemoryRetainer {
3838
Application(Session* session, const Options& options);
3939
DISALLOW_COPY_AND_MOVE(Application)
4040

41+
// Get the active options for this application. These may differ from the
42+
// options passed at construction time since some options can be negotiated.
43+
virtualconst Options& options() const = 0;
44+
4145
// The type of Application, exposed via the session state so JS
4246
// can observe which Application was selected after ALPN negotiation.
4347
// This is used primarily for testing/debugging.

‎src/quic/bindingdata.cc‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,17 @@ void BindingData::set_transport_params_template(
385385

386386
Local<DictionaryTemplate> BindingData::transport_params_template() const {
387387
returnPersistentToLocal::Default(env()->isolate(),
388-
transport_params_template_);
388+
transport_params_template_);
389+
}
390+
391+
voidBindingData::set_application_options_template(
392+
Local<DictionaryTemplate> tmpl) {
393+
application_options_template_.Reset(env()->isolate(), tmpl);
394+
}
395+
396+
Local<DictionaryTemplate> BindingData::application_options_template() const {
397+
returnPersistentToLocal::Default(env()->isolate(),
398+
application_options_template_);
389399
}
390400

391401
#defineV(name, _) \

‎src/quic/bindingdata.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,9 @@ class BindingData final
306306
voidset_transport_params_template(v8::Local<v8::DictionaryTemplate> tmpl);
307307
v8::Local<v8::DictionaryTemplate> transport_params_template() const;
308308

309+
voidset_application_options_template(v8::Local<v8::DictionaryTemplate> tmpl);
310+
v8::Local<v8::DictionaryTemplate> application_options_template() const;
311+
309312
#defineV(name, _) \
310313
void set_##name##_callback(v8::Local<v8::Function> fn); \
311314
v8::Local<v8::Function> name##_callback() const;
@@ -325,6 +328,7 @@ class BindingData final
325328
#undef V
326329

327330
v8::Global<v8::DictionaryTemplate> transport_params_template_;
331+
v8::Global<v8::DictionaryTemplate> application_options_template_;
328332

329333
#defineV(name, _) v8::Global<v8::Function> name##_callback_;
330334
QUIC_JS_CALLBACKS(V)

‎src/quic/http3.cc‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ class Http3ApplicationImpl final : public Session::Application {
157157
session->set_priority_supported();
158158
}
159159

160+
const Options& options() constoverride { return options_; }
161+
160162
Session::Application::Type type() constoverride {
161163
return Session::Application::Type::HTTP3;
162164
}

‎src/quic/session.cc‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ uint64_t MaxDatagramPayload(uint64_t max_frame_size) {
193193
V(SendDatagram, sendDatagram, SIDE_EFFECT) \
194194
V(LocalTransportParams, localTransportParams, NO_SIDE_EFFECT) \
195195
V(RemoteTransportParams, remoteTransportParams, NO_SIDE_EFFECT) \
196+
V(ApplicationOptions, applicationOptions, NO_SIDE_EFFECT)
196197

197198
structSession::State final {
198199
#defineV(_, name, type) type name;
@@ -1195,6 +1196,24 @@ struct Session::Impl final : public MemoryRetainer {
11951196
args.GetReturnValue().Set(obj);
11961197
}
11971198
}
1199+
1200+
JS_METHOD(ApplicationOptions) {
1201+
auto env = Environment::GetCurrent(args);
1202+
Session* session;
1203+
ASSIGN_OR_RETURN_UNWRAP(&session, args.This());
1204+
1205+
Local<Object> obj;
1206+
if (!session->has_application()) {
1207+
// The application has not yet been selected (ALPN negotiation is not
1208+
// yet complete on the server) or the session has been destroyed. In
1209+
// either case, the application options are not available.
1210+
return args.GetReturnValue().SetUndefined();
1211+
}
1212+
auto& options = session->application().options();
1213+
if (options.ToObject(env).ToLocal(&obj)) {
1214+
args.GetReturnValue().Set(obj);
1215+
}
1216+
}
11981217
// Internal ngtcp2 callbacks
11991218

12001219
staticinton_acknowledge_stream_data_offset(ngtcp2_conn* conn,
@@ -2082,6 +2101,10 @@ TLSSession& Session::tls_session() const {
20822101
return *tls_session_;
20832102
}
20842103

2104+
boolSession::has_application() const {
2105+
return !is_destroyed() && impl_->application_ != nullptr;
2106+
}
2107+
20852108
Session::Application& Session::application() const {
20862109
DCHECK(!is_destroyed());
20872110
DCHECK(impl_->application_);

‎src/quic/session.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ class Session final : public AsyncWrap, private SessionTicket::AppData::Source {
9191

9292
std::string ToString() const;
9393

94+
v8::MaybeLocal<v8::Object> ToObject(Environment* env) const;
95+
9496
staticconst Application_Options kDefault;
9597
};
9698

@@ -324,6 +326,7 @@ class Session final : public AsyncWrap, private SessionTicket::AppData::Source {
324326
uint32_tversion() const;
325327
Endpoint& endpoint() const;
326328
TLSSession& tls_session() const;
329+
boolhas_application() const;
327330
Application& application() const;
328331
const Config& config() const;
329332
const Options& options() const;

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all
 blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks");
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Skip to content

Commit 42aa3f6

Browse files
jasnelladuh95
authored andcommitted
quic: add applicationOptions to session
Signed-off-by: James M Snell <jasnell@gmail.com> PR-URL: #63267 Backport-PR-URL: #64675 Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
1 parent 4c00ab9 commit 42aa3f6

11 files changed

Lines changed: 320 additions & 71 deletions

File tree

‎doc/api/quic.md‎

Lines changed: 78 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,18 @@ added: v23.8.0
724724

725725
A `QuicSession` represents the local side of a QUIC connection.
726726

727+
### `session.applicationOptions`
728+
729+
<!-- YAML
730+
added: REPLACEME
731+
-->
732+
733+
* Type: {quic.ApplicationOptions}
734+
735+
The current application-level options for this session. These include settings
736+
that are specific to the negotiated application protocol (e.g. HTTP/3) and may
737+
be negotiated separately from the transport parameters. Read only.
738+
727739
### `session.close([options])`
728740

729741
<!-- YAML
@@ -2218,6 +2230,70 @@ added: v23.8.0
22182230

22192231
## Types
22202232

2233+
### type: `ApplicationOptions`
2234+
2235+
<!-- YAML
2236+
added: REPLACEME
2237+
-->
2238+
2239+
* Type: {Object}
2240+
2241+
The application specific options.
2242+
2243+
#### `applicationOptions.maxHeaderPairs`
2244+
2245+
* Type: {bigint|number}
2246+
2247+
Maximum number of header name-value pairs accepted per header block.
2248+
Headers beyond this limit are silently dropped. **Default:**`128`
2249+
2250+
#### `applicationOptions.maxHeaderLength`
2251+
2252+
* Type: {bigint|number}
2253+
2254+
Maximum total byte length of all header names and values combined per header
2255+
block. Headers that would push the total over this limit are silently
2256+
dropped. **Default:**`8192`
2257+
2258+
#### `applicationOptions.maxFieldSectionSize`
2259+
2260+
* Type: {bigint|number}
2261+
2262+
Maximum size of a compressed header field section (QPACK). `0` means
2263+
unlimited. **Default:**`0`
2264+
2265+
#### `applicationOptions.qpackMaxDTableCapacity`
2266+
2267+
* Type: {bigint|number}
2268+
2269+
QPACK dynamic table capacity in bytes. Set to `0` to disable the dynamic
2270+
table. **Default:**`4096`
2271+
2272+
#### `applicationOptions.qpackEncoderMaxDTableCapacity`
2273+
2274+
* Type: {bigint|number}
2275+
2276+
QPACK encoder maximum dynamic table capacity. **Default:**`4096`
2277+
2278+
#### `applicationOptions.qpackBlockedStreams`
2279+
2280+
* Type: {bigint|number}
2281+
2282+
Maximum number of streams that can e blocked waiting for QPACK dynamic table
2283+
updates. **Default:**`100`
2284+
2285+
#### `applicationOptions.enableConnectProtocol`
2286+
2287+
* Type: {boolean}
2288+
2289+
Enable the extended CONNECT protocol (RFC 9220). **Default:**`false`
2290+
2291+
#### `applicationOptions.enableDatagrams`
2292+
2293+
* Type: {boolean}
2294+
2295+
Enable HTTP/3 datagrams (RFC 9297). **Default:**`false`
2296+
22212297
### Type: `EndpointOptions`
22222298

22232299
<!-- YAML
@@ -2474,30 +2550,9 @@ Default: `'h3'`
24742550
added: REPLACEME
24752551
-->
24762552

2477-
* Type: {Object}
2553+
* Type: {quic.ApplicationOptions}
24782554

2479-
HTTP/3 application-specific options. These only apply when the negotiated
2480-
ALPN selects the HTTP/3 application (`'h3'`).
2481-
2482-
*`maxHeaderPairs` {number} Maximum number of header name-value pairs
2483-
accepted per header block. Headers beyond this limit are silently
2484-
dropped. **Default:**`128`
2485-
*`maxHeaderLength` {number} Maximum total byte length of all header
2486-
names and values combined per header block. Headers that would push
2487-
the total over this limit are silently dropped. **Default:**`8192`
2488-
*`maxFieldSectionSize` {number} Maximum size of a compressed header
2489-
field section (QPACK). `0` means unlimited. **Default:**`0`
2490-
*`qpackMaxDTableCapacity` {number} QPACK dynamic table capacity in
2491-
bytes. Set to `0` to disable the dynamic table. **Default:**`4096`
2492-
*`qpackEncoderMaxDTableCapacity` {number} QPACK encoder maximum
2493-
dynamic table capacity. **Default:**`4096`
2494-
*`qpackBlockedStreams` {number} Maximum number of streams that can
2495-
be blocked waiting for QPACK dynamic table updates.
2496-
**Default:**`100`
2497-
*`enableConnectProtocol` {boolean} Enable the extended CONNECT
2498-
protocol (RFC 9220). **Default:**`false`
2499-
*`enableDatagrams` {boolean} Enable HTTP/3 datagrams (RFC 9297).
2500-
**Default:**`false`
2555+
Application-specific options.
25012556

25022557
```mjs
25032558
const { listen } =awaitimport('node:quic');

‎lib/internal/quic/quic.js‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2678,6 +2678,14 @@ class QuicSession {
26782678
debug('session created');
26792679
}
26802680

2681+
getapplicationOptions(){
2682+
// We don't cache application options because they may be updated by the
2683+
// C++ layer after session creation depending on the behavior of the
2684+
// application.
2685+
if(this.destroyed)returnnull;
2686+
returnthis.#handle.applicationOptions();
2687+
}
2688+
26812689
getlocalTransportParams(){
26822690
if(this.#inner.localTransportParams!==undefined){
26832691
returnthis.#inner.localTransportParams;

‎src/quic/application.cc‎

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,13 @@
1919

2020
namespacenode {
2121

22+
using v8::BigInt;
23+
using v8::Boolean;
24+
using v8::DictionaryTemplate;
2225
using v8::Just;
2326
using v8::Local;
2427
using v8::Maybe;
28+
using v8::MaybeLocal;
2529
using v8::Nothing;
2630
using v8::Object;
2731
using v8::Value;
@@ -114,6 +118,44 @@ Maybe<Session::Application_Options> Session::Application_Options::From(
114118
return Just<Application_Options>(options);
115119
}
116120

121+
MaybeLocal<Object> Session::Application_Options::ToObject(
122+
Environment* env) const {
123+
auto& binding_data = BindingData::Get(env);
124+
auto tmpl = binding_data.application_options_template();
125+
staticconstexpr std::string_view names[] = {
126+
"maxHeaderPairs",
127+
"maxHeaderLength",
128+
"maxFieldSectionSize",
129+
"qpackMaxDtableCapacity",
130+
"qpackEncoderMaxDtableCapacity",
131+
"qpackBlockedStreams",
132+
"enableConnectProtocol",
133+
"enableDatagrams",
134+
};
135+
if (tmpl.IsEmpty()) {
136+
tmpl = DictionaryTemplate::New(env->isolate(), names);
137+
binding_data.set_application_options_template(tmpl);
138+
}
139+
MaybeLocal<Value> values[] = {
140+
BigInt::NewFromUnsigned(env->isolate(), max_header_pairs),
141+
BigInt::NewFromUnsigned(env->isolate(), max_header_length),
142+
BigInt::NewFromUnsigned(env->isolate(), max_field_section_size),
143+
BigInt::NewFromUnsigned(env->isolate(), qpack_max_dtable_capacity),
144+
BigInt::NewFromUnsigned(env->isolate(),
145+
qpack_encoder_max_dtable_capacity),
146+
BigInt::NewFromUnsigned(env->isolate(), qpack_blocked_streams),
147+
Boolean::New(env->isolate(), enable_connect_protocol),
148+
Boolean::New(env->isolate(), enable_datagrams),
149+
};
150+
static_assert(std::size(values) == std::size(names));
151+
152+
auto obj = tmpl->NewInstance(env->context(), values);
153+
if (obj->SetPrototypeV2(env->context(), Null(env->isolate())).IsNothing()) {
154+
return {};
155+
}
156+
return obj;
157+
}
158+
117159
// ============================================================================
118160

119161
std::string Session::Application::StreamData::ToString() const {
@@ -655,7 +697,10 @@ class DefaultApplication final : public Session::Application {
655697
// Marked NOLINT because the cpp linter gets confused about this using
656698
// statement not being sorted with the using v8 statements at the top
657699
// of the namespace.
658-
using Application::Application; // NOLINT
700+
DefaultApplication(Session* session, const Options& options)
701+
: Session::Application(session, options), options_(options) {}
702+
703+
const Options& options() constoverride { return options_; }
659704

660705
Session::Application::Type type() constoverride {
661706
return Session::Application::Type::DEFAULT;
@@ -827,6 +872,8 @@ class DefaultApplication final : public Session::Application {
827872
}
828873
}
829874

875+
Options options_;
876+
830877
Stream::Queue stream_queue_;
831878
};
832879

‎src/quic/application.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ class Session::Application : public MemoryRetainer {
3838
Application(Session* session, const Options& options);
3939
DISALLOW_COPY_AND_MOVE(Application)
4040

41+
// Get the active options for this application. These may differ from the
42+
// options passed at construction time since some options can be negotiated.
43+
virtualconst Options& options() const = 0;
44+
4145
// The type of Application, exposed via the session state so JS
4246
// can observe which Application was selected after ALPN negotiation.
4347
// This is used primarily for testing/debugging.

‎src/quic/bindingdata.cc‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,17 @@ void BindingData::set_transport_params_template(
385385

386386
Local<DictionaryTemplate> BindingData::transport_params_template() const {
387387
returnPersistentToLocal::Default(env()->isolate(),
388-
transport_params_template_);
388+
transport_params_template_);
389+
}
390+
391+
voidBindingData::set_application_options_template(
392+
Local<DictionaryTemplate> tmpl) {
393+
application_options_template_.Reset(env()->isolate(), tmpl);
394+
}
395+
396+
Local<DictionaryTemplate> BindingData::application_options_template() const {
397+
returnPersistentToLocal::Default(env()->isolate(),
398+
application_options_template_);
389399
}
390400

391401
#defineV(name, _) \

‎src/quic/bindingdata.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,9 @@ class BindingData final
306306
voidset_transport_params_template(v8::Local<v8::DictionaryTemplate> tmpl);
307307
v8::Local<v8::DictionaryTemplate> transport_params_template() const;
308308

309+
voidset_application_options_template(v8::Local<v8::DictionaryTemplate> tmpl);
310+
v8::Local<v8::DictionaryTemplate> application_options_template() const;
311+
309312
#defineV(name, _) \
310313
void set_##name##_callback(v8::Local<v8::Function> fn); \
311314
v8::Local<v8::Function> name##_callback() const;
@@ -325,6 +328,7 @@ class BindingData final
325328
#undef V
326329

327330
v8::Global<v8::DictionaryTemplate> transport_params_template_;
331+
v8::Global<v8::DictionaryTemplate> application_options_template_;
328332

329333
#defineV(name, _) v8::Global<v8::Function> name##_callback_;
330334
QUIC_JS_CALLBACKS(V)

‎src/quic/http3.cc‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ class Http3ApplicationImpl final : public Session::Application {
157157
session->set_priority_supported();
158158
}
159159

160+
const Options& options() constoverride { return options_; }
161+
160162
Session::Application::Type type() constoverride {
161163
return Session::Application::Type::HTTP3;
162164
}

‎src/quic/session.cc‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ uint64_t MaxDatagramPayload(uint64_t max_frame_size) {
193193
V(SendDatagram, sendDatagram, SIDE_EFFECT) \
194194
V(LocalTransportParams, localTransportParams, NO_SIDE_EFFECT) \
195195
V(RemoteTransportParams, remoteTransportParams, NO_SIDE_EFFECT) \
196+
V(ApplicationOptions, applicationOptions, NO_SIDE_EFFECT)
196197

197198
structSession::State final {
198199
#defineV(_, name, type) type name;
@@ -1195,6 +1196,24 @@ struct Session::Impl final : public MemoryRetainer {
11951196
args.GetReturnValue().Set(obj);
11961197
}
11971198
}
1199+
1200+
JS_METHOD(ApplicationOptions) {
1201+
auto env = Environment::GetCurrent(args);
1202+
Session* session;
1203+
ASSIGN_OR_RETURN_UNWRAP(&session, args.This());
1204+
1205+
Local<Object> obj;
1206+
if (!session->has_application()) {
1207+
// The application has not yet been selected (ALPN negotiation is not
1208+
// yet complete on the server) or the session has been destroyed. In
1209+
// either case, the application options are not available.
1210+
return args.GetReturnValue().SetUndefined();
1211+
}
1212+
auto& options = session->application().options();
1213+
if (options.ToObject(env).ToLocal(&obj)) {
1214+
args.GetReturnValue().Set(obj);
1215+
}
1216+
}
11981217
// Internal ngtcp2 callbacks
11991218

12001219
staticinton_acknowledge_stream_data_offset(ngtcp2_conn* conn,
@@ -2082,6 +2101,10 @@ TLSSession& Session::tls_session() const {
20822101
return *tls_session_;
20832102
}
20842103

2104+
boolSession::has_application() const {
2105+
return !is_destroyed() && impl_->application_ != nullptr;
2106+
}
2107+
20852108
Session::Application& Session::application() const {
20862109
DCHECK(!is_destroyed());
20872110
DCHECK(impl_->application_);

‎src/quic/session.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ class Session final : public AsyncWrap, private SessionTicket::AppData::Source {
9191

9292
std::string ToString() const;
9393

94+
v8::MaybeLocal<v8::Object> ToObject(Environment* env) const;
95+
9496
staticconst Application_Options kDefault;
9597
};
9698

@@ -324,6 +326,7 @@ class Session final : public AsyncWrap, private SessionTicket::AppData::Source {
324326
uint32_tversion() const;
325327
Endpoint& endpoint() const;
326328
TLSSession& tls_session() const;
329+
boolhas_application() const;
327330
Application& application() const;
328331
const Config& config() const;
329332
const Options& options() const;

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Commit 42aa3f6

Browse files
jasnelladuh95
authored andcommitted
quic: add applicationOptions to session
Signed-off-by: James M Snell <jasnell@gmail.com> PR-URL: #63267 Backport-PR-URL: #64675 Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
1 parent 4c00ab9 commit 42aa3f6

11 files changed

Lines changed: 320 additions & 71 deletions

File tree

‎doc/api/quic.md‎

Lines changed: 78 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,18 @@ added: v23.8.0
724724

725725
A `QuicSession` represents the local side of a QUIC connection.
726726

727+
### `session.applicationOptions`
728+
729+
<!-- YAML
730+
added: REPLACEME
731+
-->
732+
733+
* Type: {quic.ApplicationOptions}
734+
735+
The current application-level options for this session. These include settings
736+
that are specific to the negotiated application protocol (e.g. HTTP/3) and may
737+
be negotiated separately from the transport parameters. Read only.
738+
727739
### `session.close([options])`
728740

729741
<!-- YAML
@@ -2218,6 +2230,70 @@ added: v23.8.0
22182230

22192231
## Types
22202232

2233+
### type: `ApplicationOptions`
2234+
2235+
<!-- YAML
2236+
added: REPLACEME
2237+
-->
2238+
2239+
* Type: {Object}
2240+
2241+
The application specific options.
2242+
2243+
#### `applicationOptions.maxHeaderPairs`
2244+
2245+
* Type: {bigint|number}
2246+
2247+
Maximum number of header name-value pairs accepted per header block.
2248+
Headers beyond this limit are silently dropped. **Default:**`128`
2249+
2250+
#### `applicationOptions.maxHeaderLength`
2251+
2252+
* Type: {bigint|number}
2253+
2254+
Maximum total byte length of all header names and values combined per header
2255+
block. Headers that would push the total over this limit are silently
2256+
dropped. **Default:**`8192`
2257+
2258+
#### `applicationOptions.maxFieldSectionSize`
2259+
2260+
* Type: {bigint|number}
2261+
2262+
Maximum size of a compressed header field section (QPACK). `0` means
2263+
unlimited. **Default:**`0`
2264+
2265+
#### `applicationOptions.qpackMaxDTableCapacity`
2266+
2267+
* Type: {bigint|number}
2268+
2269+
QPACK dynamic table capacity in bytes. Set to `0` to disable the dynamic
2270+
table. **Default:**`4096`
2271+
2272+
#### `applicationOptions.qpackEncoderMaxDTableCapacity`
2273+
2274+
* Type: {bigint|number}
2275+
2276+
QPACK encoder maximum dynamic table capacity. **Default:**`4096`
2277+
2278+
#### `applicationOptions.qpackBlockedStreams`
2279+
2280+
* Type: {bigint|number}
2281+
2282+
Maximum number of streams that can e blocked waiting for QPACK dynamic table
2283+
updates. **Default:**`100`
2284+
2285+
#### `applicationOptions.enableConnectProtocol`
2286+
2287+
* Type: {boolean}
2288+
2289+
Enable the extended CONNECT protocol (RFC 9220). **Default:**`false`
2290+
2291+
#### `applicationOptions.enableDatagrams`
2292+
2293+
* Type: {boolean}
2294+
2295+
Enable HTTP/3 datagrams (RFC 9297). **Default:**`false`
2296+
22212297
### Type: `EndpointOptions`
22222298

22232299
<!-- YAML
@@ -2474,30 +2550,9 @@ Default: `'h3'`
24742550
added: REPLACEME
24752551
-->
24762552

2477-
* Type: {Object}
2553+
* Type: {quic.ApplicationOptions}
24782554

2479-
HTTP/3 application-specific options. These only apply when the negotiated
2480-
ALPN selects the HTTP/3 application (`'h3'`).
2481-
2482-
*`maxHeaderPairs` {number} Maximum number of header name-value pairs
2483-
accepted per header block. Headers beyond this limit are silently
2484-
dropped. **Default:**`128`
2485-
*`maxHeaderLength` {number} Maximum total byte length of all header
2486-
names and values combined per header block. Headers that would push
2487-
the total over this limit are silently dropped. **Default:**`8192`
2488-
*`maxFieldSectionSize` {number} Maximum size of a compressed header
2489-
field section (QPACK). `0` means unlimited. **Default:**`0`
2490-
*`qpackMaxDTableCapacity` {number} QPACK dynamic table capacity in
2491-
bytes. Set to `0` to disable the dynamic table. **Default:**`4096`
2492-
*`qpackEncoderMaxDTableCapacity` {number} QPACK encoder maximum
2493-
dynamic table capacity. **Default:**`4096`
2494-
*`qpackBlockedStreams` {number} Maximum number of streams that can
2495-
be blocked waiting for QPACK dynamic table updates.
2496-
**Default:**`100`
2497-
*`enableConnectProtocol` {boolean} Enable the extended CONNECT
2498-
protocol (RFC 9220). **Default:**`false`
2499-
*`enableDatagrams` {boolean} Enable HTTP/3 datagrams (RFC 9297).
2500-
**Default:**`false`
2555+
Application-specific options.
25012556

25022557
```mjs
25032558
const { listen } =awaitimport('node:quic');

‎lib/internal/quic/quic.js‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2678,6 +2678,14 @@ class QuicSession {
26782678
debug('session created');
26792679
}
26802680

2681+
getapplicationOptions(){
2682+
// We don't cache application options because they may be updated by the
2683+
// C++ layer after session creation depending on the behavior of the
2684+
// application.
2685+
if(this.destroyed)returnnull;
2686+
returnthis.#handle.applicationOptions();
2687+
}
2688+
26812689
getlocalTransportParams(){
26822690
if(this.#inner.localTransportParams!==undefined){
26832691
returnthis.#inner.localTransportParams;

‎src/quic/application.cc‎

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,13 @@
1919

2020
namespacenode {
2121

22+
using v8::BigInt;
23+
using v8::Boolean;
24+
using v8::DictionaryTemplate;
2225
using v8::Just;
2326
using v8::Local;
2427
using v8::Maybe;
28+
using v8::MaybeLocal;
2529
using v8::Nothing;
2630
using v8::Object;
2731
using v8::Value;
@@ -114,6 +118,44 @@ Maybe<Session::Application_Options> Session::Application_Options::From(
114118
return Just<Application_Options>(options);
115119
}
116120

121+
MaybeLocal<Object> Session::Application_Options::ToObject(
122+
Environment* env) const {
123+
auto& binding_data = BindingData::Get(env);
124+
auto tmpl = binding_data.application_options_template();
125+
staticconstexpr std::string_view names[] = {
126+
"maxHeaderPairs",
127+
"maxHeaderLength",
128+
"maxFieldSectionSize",
129+
"qpackMaxDtableCapacity",
130+
"qpackEncoderMaxDtableCapacity",
131+
"qpackBlockedStreams",
132+
"enableConnectProtocol",
133+
"enableDatagrams",
134+
};
135+
if (tmpl.IsEmpty()) {
136+
tmpl = DictionaryTemplate::New(env->isolate(), names);
137+
binding_data.set_application_options_template(tmpl);
138+
}
139+
MaybeLocal<Value> values[] = {
140+
BigInt::NewFromUnsigned(env->isolate(), max_header_pairs),
141+
BigInt::NewFromUnsigned(env->isolate(), max_header_length),
142+
BigInt::NewFromUnsigned(env->isolate(), max_field_section_size),
143+
BigInt::NewFromUnsigned(env->isolate(), qpack_max_dtable_capacity),
144+
BigInt::NewFromUnsigned(env->isolate(),
145+
qpack_encoder_max_dtable_capacity),
146+
BigInt::NewFromUnsigned(env->isolate(), qpack_blocked_streams),
147+
Boolean::New(env->isolate(), enable_connect_protocol),
148+
Boolean::New(env->isolate(), enable_datagrams),
149+
};
150+
static_assert(std::size(values) == std::size(names));
151+
152+
auto obj = tmpl->NewInstance(env->context(), values);
153+
if (obj->SetPrototypeV2(env->context(), Null(env->isolate())).IsNothing()) {
154+
return {};
155+
}
156+
return obj;
157+
}
158+
117159
// ============================================================================
118160

119161
std::string Session::Application::StreamData::ToString() const {
@@ -655,7 +697,10 @@ class DefaultApplication final : public Session::Application {
655697
// Marked NOLINT because the cpp linter gets confused about this using
656698
// statement not being sorted with the using v8 statements at the top
657699
// of the namespace.
658-
using Application::Application; // NOLINT
700+
DefaultApplication(Session* session, const Options& options)
701+
: Session::Application(session, options), options_(options) {}
702+
703+
const Options& options() constoverride { return options_; }
659704

660705
Session::Application::Type type() constoverride {
661706
return Session::Application::Type::DEFAULT;
@@ -827,6 +872,8 @@ class DefaultApplication final : public Session::Application {
827872
}
828873
}
829874

875+
Options options_;
876+
830877
Stream::Queue stream_queue_;
831878
};
832879

‎src/quic/application.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ class Session::Application : public MemoryRetainer {
3838
Application(Session* session, const Options& options);
3939
DISALLOW_COPY_AND_MOVE(Application)
4040

41+
// Get the active options for this application. These may differ from the
42+
// options passed at construction time since some options can be negotiated.
43+
virtualconst Options& options() const = 0;
44+
4145
// The type of Application, exposed via the session state so JS
4246
// can observe which Application was selected after ALPN negotiation.
4347
// This is used primarily for testing/debugging.

‎src/quic/bindingdata.cc‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,17 @@ void BindingData::set_transport_params_template(
385385

386386
Local<DictionaryTemplate> BindingData::transport_params_template() const {
387387
returnPersistentToLocal::Default(env()->isolate(),
388-
transport_params_template_);
388+
transport_params_template_);
389+
}
390+
391+
voidBindingData::set_application_options_template(
392+
Local<DictionaryTemplate> tmpl) {
393+
application_options_template_.Reset(env()->isolate(), tmpl);
394+
}
395+
396+
Local<DictionaryTemplate> BindingData::application_options_template() const {
397+
returnPersistentToLocal::Default(env()->isolate(),
398+
application_options_template_);
389399
}
390400

391401
#defineV(name, _) \

‎src/quic/bindingdata.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,9 @@ class BindingData final
306306
voidset_transport_params_template(v8::Local<v8::DictionaryTemplate> tmpl);
307307
v8::Local<v8::DictionaryTemplate> transport_params_template() const;
308308

309+
voidset_application_options_template(v8::Local<v8::DictionaryTemplate> tmpl);
310+
v8::Local<v8::DictionaryTemplate> application_options_template() const;
311+
309312
#defineV(name, _) \
310313
void set_##name##_callback(v8::Local<v8::Function> fn); \
311314
v8::Local<v8::Function> name##_callback() const;
@@ -325,6 +328,7 @@ class BindingData final
325328
#undef V
326329

327330
v8::Global<v8::DictionaryTemplate> transport_params_template_;
331+
v8::Global<v8::DictionaryTemplate> application_options_template_;
328332

329333
#defineV(name, _) v8::Global<v8::Function> name##_callback_;
330334
QUIC_JS_CALLBACKS(V)

‎src/quic/http3.cc‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ class Http3ApplicationImpl final : public Session::Application {
157157
session->set_priority_supported();
158158
}
159159

160+
const Options& options() constoverride { return options_; }
161+
160162
Session::Application::Type type() constoverride {
161163
return Session::Application::Type::HTTP3;
162164
}

‎src/quic/session.cc‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ uint64_t MaxDatagramPayload(uint64_t max_frame_size) {
193193
V(SendDatagram, sendDatagram, SIDE_EFFECT) \
194194
V(LocalTransportParams, localTransportParams, NO_SIDE_EFFECT) \
195195
V(RemoteTransportParams, remoteTransportParams, NO_SIDE_EFFECT) \
196+
V(ApplicationOptions, applicationOptions, NO_SIDE_EFFECT)
196197

197198
structSession::State final {
198199
#defineV(_, name, type) type name;
@@ -1195,6 +1196,24 @@ struct Session::Impl final : public MemoryRetainer {
11951196
args.GetReturnValue().Set(obj);
11961197
}
11971198
}
1199+
1200+
JS_METHOD(ApplicationOptions) {
1201+
auto env = Environment::GetCurrent(args);
1202+
Session* session;
1203+
ASSIGN_OR_RETURN_UNWRAP(&session, args.This());
1204+
1205+
Local<Object> obj;
1206+
if (!session->has_application()) {
1207+
// The application has not yet been selected (ALPN negotiation is not
1208+
// yet complete on the server) or the session has been destroyed. In
1209+
// either case, the application options are not available.
1210+
return args.GetReturnValue().SetUndefined();
1211+
}
1212+
auto& options = session->application().options();
1213+
if (options.ToObject(env).ToLocal(&obj)) {
1214+
args.GetReturnValue().Set(obj);
1215+
}
1216+
}
11981217
// Internal ngtcp2 callbacks
11991218

12001219
staticinton_acknowledge_stream_data_offset(ngtcp2_conn* conn,
@@ -2082,6 +2101,10 @@ TLSSession& Session::tls_session() const {
20822101
return *tls_session_;
20832102
}
20842103

2104+
boolSession::has_application() const {
2105+
return !is_destroyed() && impl_->application_ != nullptr;
2106+
}
2107+
20852108
Session::Application& Session::application() const {
20862109
DCHECK(!is_destroyed());
20872110
DCHECK(impl_->application_);

‎src/quic/session.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ class Session final : public AsyncWrap, private SessionTicket::AppData::Source {
9191

9292
std::string ToString() const;
9393

94+
v8::MaybeLocal<v8::Object> ToObject(Environment* env) const;
95+
9496
staticconst Application_Options kDefault;
9597
};
9698

@@ -324,6 +326,7 @@ class Session final : public AsyncWrap, private SessionTicket::AppData::Source {
324326
uint32_tversion() const;
325327
Endpoint& endpoint() const;
326328
TLSSession& tls_session() const;
329+
boolhas_application() const;
327330
Application& application() const;
328331
const Config& config() const;
329332
const Options& options() const;

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length > 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Commit 42aa3f6

Browse files
jasnelladuh95
authored andcommitted
quic: add applicationOptions to session
Signed-off-by: James M Snell <jasnell@gmail.com> PR-URL: #63267 Backport-PR-URL: #64675 Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
1 parent 4c00ab9 commit 42aa3f6

11 files changed

Lines changed: 320 additions & 71 deletions

File tree

‎doc/api/quic.md‎

Lines changed: 78 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,18 @@ added: v23.8.0
724724

725725
A `QuicSession` represents the local side of a QUIC connection.
726726

727+
### `session.applicationOptions`
728+
729+
<!-- YAML
730+
added: REPLACEME
731+
-->
732+
733+
* Type: {quic.ApplicationOptions}
734+
735+
The current application-level options for this session. These include settings
736+
that are specific to the negotiated application protocol (e.g. HTTP/3) and may
737+
be negotiated separately from the transport parameters. Read only.
738+
727739
### `session.close([options])`
728740

729741
<!-- YAML
@@ -2218,6 +2230,70 @@ added: v23.8.0
22182230

22192231
## Types
22202232

2233+
### type: `ApplicationOptions`
2234+
2235+
<!-- YAML
2236+
added: REPLACEME
2237+
-->
2238+
2239+
* Type: {Object}
2240+
2241+
The application specific options.
2242+
2243+
#### `applicationOptions.maxHeaderPairs`
2244+
2245+
* Type: {bigint|number}
2246+
2247+
Maximum number of header name-value pairs accepted per header block.
2248+
Headers beyond this limit are silently dropped. **Default:**`128`
2249+
2250+
#### `applicationOptions.maxHeaderLength`
2251+
2252+
* Type: {bigint|number}
2253+
2254+
Maximum total byte length of all header names and values combined per header
2255+
block. Headers that would push the total over this limit are silently
2256+
dropped. **Default:**`8192`
2257+
2258+
#### `applicationOptions.maxFieldSectionSize`
2259+
2260+
* Type: {bigint|number}
2261+
2262+
Maximum size of a compressed header field section (QPACK). `0` means
2263+
unlimited. **Default:**`0`
2264+
2265+
#### `applicationOptions.qpackMaxDTableCapacity`
2266+
2267+
* Type: {bigint|number}
2268+
2269+
QPACK dynamic table capacity in bytes. Set to `0` to disable the dynamic
2270+
table. **Default:**`4096`
2271+
2272+
#### `applicationOptions.qpackEncoderMaxDTableCapacity`
2273+
2274+
* Type: {bigint|number}
2275+
2276+
QPACK encoder maximum dynamic table capacity. **Default:**`4096`
2277+
2278+
#### `applicationOptions.qpackBlockedStreams`
2279+
2280+
* Type: {bigint|number}
2281+
2282+
Maximum number of streams that can e blocked waiting for QPACK dynamic table
2283+
updates. **Default:**`100`
2284+
2285+
#### `applicationOptions.enableConnectProtocol`
2286+
2287+
* Type: {boolean}
2288+
2289+
Enable the extended CONNECT protocol (RFC 9220). **Default:**`false`
2290+
2291+
#### `applicationOptions.enableDatagrams`
2292+
2293+
* Type: {boolean}
2294+
2295+
Enable HTTP/3 datagrams (RFC 9297). **Default:**`false`
2296+
22212297
### Type: `EndpointOptions`
22222298

22232299
<!-- YAML
@@ -2474,30 +2550,9 @@ Default: `'h3'`
24742550
added: REPLACEME
24752551
-->
24762552

2477-
* Type: {Object}
2553+
* Type: {quic.ApplicationOptions}
24782554

2479-
HTTP/3 application-specific options. These only apply when the negotiated
2480-
ALPN selects the HTTP/3 application (`'h3'`).
2481-
2482-
*`maxHeaderPairs` {number} Maximum number of header name-value pairs
2483-
accepted per header block. Headers beyond this limit are silently
2484-
dropped. **Default:**`128`
2485-
*`maxHeaderLength` {number} Maximum total byte length of all header
2486-
names and values combined per header block. Headers that would push
2487-
the total over this limit are silently dropped. **Default:**`8192`
2488-
*`maxFieldSectionSize` {number} Maximum size of a compressed header
2489-
field section (QPACK). `0` means unlimited. **Default:**`0`
2490-
*`qpackMaxDTableCapacity` {number} QPACK dynamic table capacity in
2491-
bytes. Set to `0` to disable the dynamic table. **Default:**`4096`
2492-
*`qpackEncoderMaxDTableCapacity` {number} QPACK encoder maximum
2493-
dynamic table capacity. **Default:**`4096`
2494-
*`qpackBlockedStreams` {number} Maximum number of streams that can
2495-
be blocked waiting for QPACK dynamic table updates.
2496-
**Default:**`100`
2497-
*`enableConnectProtocol` {boolean} Enable the extended CONNECT
2498-
protocol (RFC 9220). **Default:**`false`
2499-
*`enableDatagrams` {boolean} Enable HTTP/3 datagrams (RFC 9297).
2500-
**Default:**`false`
2555+
Application-specific options.
25012556

25022557
```mjs
25032558
const { listen } =awaitimport('node:quic');

‎lib/internal/quic/quic.js‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2678,6 +2678,14 @@ class QuicSession {
26782678
debug('session created');
26792679
}
26802680

2681+
getapplicationOptions(){
2682+
// We don't cache application options because they may be updated by the
2683+
// C++ layer after session creation depending on the behavior of the
2684+
// application.
2685+
if(this.destroyed)returnnull;
2686+
returnthis.#handle.applicationOptions();
2687+
}
2688+
26812689
getlocalTransportParams(){
26822690
if(this.#inner.localTransportParams!==undefined){
26832691
returnthis.#inner.localTransportParams;

‎src/quic/application.cc‎

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,13 @@
1919

2020
namespacenode {
2121

22+
using v8::BigInt;
23+
using v8::Boolean;
24+
using v8::DictionaryTemplate;
2225
using v8::Just;
2326
using v8::Local;
2427
using v8::Maybe;
28+
using v8::MaybeLocal;
2529
using v8::Nothing;
2630
using v8::Object;
2731
using v8::Value;
@@ -114,6 +118,44 @@ Maybe<Session::Application_Options> Session::Application_Options::From(
114118
return Just<Application_Options>(options);
115119
}
116120

121+
MaybeLocal<Object> Session::Application_Options::ToObject(
122+
Environment* env) const {
123+
auto& binding_data = BindingData::Get(env);
124+
auto tmpl = binding_data.application_options_template();
125+
staticconstexpr std::string_view names[] = {
126+
"maxHeaderPairs",
127+
"maxHeaderLength",
128+
"maxFieldSectionSize",
129+
"qpackMaxDtableCapacity",
130+
"qpackEncoderMaxDtableCapacity",
131+
"qpackBlockedStreams",
132+
"enableConnectProtocol",
133+
"enableDatagrams",
134+
};
135+
if (tmpl.IsEmpty()) {
136+
tmpl = DictionaryTemplate::New(env->isolate(), names);
137+
binding_data.set_application_options_template(tmpl);
138+
}
139+
MaybeLocal<Value> values[] = {
140+
BigInt::NewFromUnsigned(env->isolate(), max_header_pairs),
141+
BigInt::NewFromUnsigned(env->isolate(), max_header_length),
142+
BigInt::NewFromUnsigned(env->isolate(), max_field_section_size),
143+
BigInt::NewFromUnsigned(env->isolate(), qpack_max_dtable_capacity),
144+
BigInt::NewFromUnsigned(env->isolate(),
145+
qpack_encoder_max_dtable_capacity),
146+
BigInt::NewFromUnsigned(env->isolate(), qpack_blocked_streams),
147+
Boolean::New(env->isolate(), enable_connect_protocol),
148+
Boolean::New(env->isolate(), enable_datagrams),
149+
};
150+
static_assert(std::size(values) == std::size(names));
151+
152+
auto obj = tmpl->NewInstance(env->context(), values);
153+
if (obj->SetPrototypeV2(env->context(), Null(env->isolate())).IsNothing()) {
154+
return {};
155+
}
156+
return obj;
157+
}
158+
117159
// ============================================================================
118160

119161
std::string Session::Application::StreamData::ToString() const {
@@ -655,7 +697,10 @@ class DefaultApplication final : public Session::Application {
655697
// Marked NOLINT because the cpp linter gets confused about this using
656698
// statement not being sorted with the using v8 statements at the top
657699
// of the namespace.
658-
using Application::Application; // NOLINT
700+
DefaultApplication(Session* session, const Options& options)
701+
: Session::Application(session, options), options_(options) {}
702+
703+
const Options& options() constoverride { return options_; }
659704

660705
Session::Application::Type type() constoverride {
661706
return Session::Application::Type::DEFAULT;
@@ -827,6 +872,8 @@ class DefaultApplication final : public Session::Application {
827872
}
828873
}
829874

875+
Options options_;
876+
830877
Stream::Queue stream_queue_;
831878
};
832879

‎src/quic/application.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ class Session::Application : public MemoryRetainer {
3838
Application(Session* session, const Options& options);
3939
DISALLOW_COPY_AND_MOVE(Application)
4040

41+
// Get the active options for this application. These may differ from the
42+
// options passed at construction time since some options can be negotiated.
43+
virtualconst Options& options() const = 0;
44+
4145
// The type of Application, exposed via the session state so JS
4246
// can observe which Application was selected after ALPN negotiation.
4347
// This is used primarily for testing/debugging.

‎src/quic/bindingdata.cc‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,17 @@ void BindingData::set_transport_params_template(
385385

386386
Local<DictionaryTemplate> BindingData::transport_params_template() const {
387387
returnPersistentToLocal::Default(env()->isolate(),
388-
transport_params_template_);
388+
transport_params_template_);
389+
}
390+
391+
voidBindingData::set_application_options_template(
392+
Local<DictionaryTemplate> tmpl) {
393+
application_options_template_.Reset(env()->isolate(), tmpl);
394+
}
395+
396+
Local<DictionaryTemplate> BindingData::application_options_template() const {
397+
returnPersistentToLocal::Default(env()->isolate(),
398+
application_options_template_);
389399
}
390400

391401
#defineV(name, _) \

‎src/quic/bindingdata.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,9 @@ class BindingData final
306306
voidset_transport_params_template(v8::Local<v8::DictionaryTemplate> tmpl);
307307
v8::Local<v8::DictionaryTemplate> transport_params_template() const;
308308

309+
voidset_application_options_template(v8::Local<v8::DictionaryTemplate> tmpl);
310+
v8::Local<v8::DictionaryTemplate> application_options_template() const;
311+
309312
#defineV(name, _) \
310313
void set_##name##_callback(v8::Local<v8::Function> fn); \
311314
v8::Local<v8::Function> name##_callback() const;
@@ -325,6 +328,7 @@ class BindingData final
325328
#undef V
326329

327330
v8::Global<v8::DictionaryTemplate> transport_params_template_;
331+
v8::Global<v8::DictionaryTemplate> application_options_template_;
328332

329333
#defineV(name, _) v8::Global<v8::Function> name##_callback_;
330334
QUIC_JS_CALLBACKS(V)

‎src/quic/http3.cc‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ class Http3ApplicationImpl final : public Session::Application {
157157
session->set_priority_supported();
158158
}
159159

160+
const Options& options() constoverride { return options_; }
161+
160162
Session::Application::Type type() constoverride {
161163
return Session::Application::Type::HTTP3;
162164
}

‎src/quic/session.cc‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ uint64_t MaxDatagramPayload(uint64_t max_frame_size) {
193193
V(SendDatagram, sendDatagram, SIDE_EFFECT) \
194194
V(LocalTransportParams, localTransportParams, NO_SIDE_EFFECT) \
195195
V(RemoteTransportParams, remoteTransportParams, NO_SIDE_EFFECT) \
196+
V(ApplicationOptions, applicationOptions, NO_SIDE_EFFECT)
196197

197198
structSession::State final {
198199
#defineV(_, name, type) type name;
@@ -1195,6 +1196,24 @@ struct Session::Impl final : public MemoryRetainer {
11951196
args.GetReturnValue().Set(obj);
11961197
}
11971198
}
1199+
1200+
JS_METHOD(ApplicationOptions) {
1201+
auto env = Environment::GetCurrent(args);
1202+
Session* session;
1203+
ASSIGN_OR_RETURN_UNWRAP(&session, args.This());
1204+
1205+
Local<Object> obj;
1206+
if (!session->has_application()) {
1207+
// The application has not yet been selected (ALPN negotiation is not
1208+
// yet complete on the server) or the session has been destroyed. In
1209+
// either case, the application options are not available.
1210+
return args.GetReturnValue().SetUndefined();
1211+
}
1212+
auto& options = session->application().options();
1213+
if (options.ToObject(env).ToLocal(&obj)) {
1214+
args.GetReturnValue().Set(obj);
1215+
}
1216+
}
11981217
// Internal ngtcp2 callbacks
11991218

12001219
staticinton_acknowledge_stream_data_offset(ngtcp2_conn* conn,
@@ -2082,6 +2101,10 @@ TLSSession& Session::tls_session() const {
20822101
return *tls_session_;
20832102
}
20842103

2104+
boolSession::has_application() const {
2105+
return !is_destroyed() && impl_->application_ != nullptr;
2106+
}
2107+
20852108
Session::Application& Session::application() const {
20862109
DCHECK(!is_destroyed());
20872110
DCHECK(impl_->application_);

‎src/quic/session.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ class Session final : public AsyncWrap, private SessionTicket::AppData::Source {
9191

9292
std::string ToString() const;
9393

94+
v8::MaybeLocal<v8::Object> ToObject(Environment* env) const;
95+
9496
staticconst Application_Options kDefault;
9597
};
9698

@@ -324,6 +326,7 @@ class Session final : public AsyncWrap, private SessionTicket::AppData::Source {
324326
uint32_tversion() const;
325327
Endpoint& endpoint() const;
326328
TLSSession& tls_session() const;
329+
boolhas_application() const;
327330
Application& application() const;
328331
const Config& config() const;
329332
const Options& options() const;

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content

Commit 42aa3f6

Browse files
jasnelladuh95
authored andcommitted
quic: add applicationOptions to session
Signed-off-by: James M Snell <jasnell@gmail.com> PR-URL: #63267 Backport-PR-URL: #64675 Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
1 parent 4c00ab9 commit 42aa3f6

11 files changed

Lines changed: 320 additions & 71 deletions

File tree

‎doc/api/quic.md‎

Lines changed: 78 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,18 @@ added: v23.8.0
724724

725725
A `QuicSession` represents the local side of a QUIC connection.
726726

727+
### `session.applicationOptions`
728+
729+
<!-- YAML
730+
added: REPLACEME
731+
-->
732+
733+
* Type: {quic.ApplicationOptions}
734+
735+
The current application-level options for this session. These include settings
736+
that are specific to the negotiated application protocol (e.g. HTTP/3) and may
737+
be negotiated separately from the transport parameters. Read only.
738+
727739
### `session.close([options])`
728740

729741
<!-- YAML
@@ -2218,6 +2230,70 @@ added: v23.8.0
22182230

22192231
## Types
22202232

2233+
### type: `ApplicationOptions`
2234+
2235+
<!-- YAML
2236+
added: REPLACEME
2237+
-->
2238+
2239+
* Type: {Object}
2240+
2241+
The application specific options.
2242+
2243+
#### `applicationOptions.maxHeaderPairs`
2244+
2245+
* Type: {bigint|number}
2246+
2247+
Maximum number of header name-value pairs accepted per header block.
2248+
Headers beyond this limit are silently dropped. **Default:**`128`
2249+
2250+
#### `applicationOptions.maxHeaderLength`
2251+
2252+
* Type: {bigint|number}
2253+
2254+
Maximum total byte length of all header names and values combined per header
2255+
block. Headers that would push the total over this limit are silently
2256+
dropped. **Default:**`8192`
2257+
2258+
#### `applicationOptions.maxFieldSectionSize`
2259+
2260+
* Type: {bigint|number}
2261+
2262+
Maximum size of a compressed header field section (QPACK). `0` means
2263+
unlimited. **Default:**`0`
2264+
2265+
#### `applicationOptions.qpackMaxDTableCapacity`
2266+
2267+
* Type: {bigint|number}
2268+
2269+
QPACK dynamic table capacity in bytes. Set to `0` to disable the dynamic
2270+
table. **Default:**`4096`
2271+
2272+
#### `applicationOptions.qpackEncoderMaxDTableCapacity`
2273+
2274+
* Type: {bigint|number}
2275+
2276+
QPACK encoder maximum dynamic table capacity. **Default:**`4096`
2277+
2278+
#### `applicationOptions.qpackBlockedStreams`
2279+
2280+
* Type: {bigint|number}
2281+
2282+
Maximum number of streams that can e blocked waiting for QPACK dynamic table
2283+
updates. **Default:**`100`
2284+
2285+
#### `applicationOptions.enableConnectProtocol`
2286+
2287+
* Type: {boolean}
2288+
2289+
Enable the extended CONNECT protocol (RFC 9220). **Default:**`false`
2290+
2291+
#### `applicationOptions.enableDatagrams`
2292+
2293+
* Type: {boolean}
2294+
2295+
Enable HTTP/3 datagrams (RFC 9297). **Default:**`false`
2296+
22212297
### Type: `EndpointOptions`
22222298

22232299
<!-- YAML
@@ -2474,30 +2550,9 @@ Default: `'h3'`
24742550
added: REPLACEME
24752551
-->
24762552

2477-
* Type: {Object}
2553+
* Type: {quic.ApplicationOptions}
24782554

2479-
HTTP/3 application-specific options. These only apply when the negotiated
2480-
ALPN selects the HTTP/3 application (`'h3'`).
2481-
2482-
*`maxHeaderPairs` {number} Maximum number of header name-value pairs
2483-
accepted per header block. Headers beyond this limit are silently
2484-
dropped. **Default:**`128`
2485-
*`maxHeaderLength` {number} Maximum total byte length of all header
2486-
names and values combined per header block. Headers that would push
2487-
the total over this limit are silently dropped. **Default:**`8192`
2488-
*`maxFieldSectionSize` {number} Maximum size of a compressed header
2489-
field section (QPACK). `0` means unlimited. **Default:**`0`
2490-
*`qpackMaxDTableCapacity` {number} QPACK dynamic table capacity in
2491-
bytes. Set to `0` to disable the dynamic table. **Default:**`4096`
2492-
*`qpackEncoderMaxDTableCapacity` {number} QPACK encoder maximum
2493-
dynamic table capacity. **Default:**`4096`
2494-
*`qpackBlockedStreams` {number} Maximum number of streams that can
2495-
be blocked waiting for QPACK dynamic table updates.
2496-
**Default:**`100`
2497-
*`enableConnectProtocol` {boolean} Enable the extended CONNECT
2498-
protocol (RFC 9220). **Default:**`false`
2499-
*`enableDatagrams` {boolean} Enable HTTP/3 datagrams (RFC 9297).
2500-
**Default:**`false`
2555+
Application-specific options.
25012556

25022557
```mjs
25032558
const { listen } =awaitimport('node:quic');

‎lib/internal/quic/quic.js‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2678,6 +2678,14 @@ class QuicSession {
26782678
debug('session created');
26792679
}
26802680

2681+
getapplicationOptions(){
2682+
// We don't cache application options because they may be updated by the
2683+
// C++ layer after session creation depending on the behavior of the
2684+
// application.
2685+
if(this.destroyed)returnnull;
2686+
returnthis.#handle.applicationOptions();
2687+
}
2688+
26812689
getlocalTransportParams(){
26822690
if(this.#inner.localTransportParams!==undefined){
26832691
returnthis.#inner.localTransportParams;

‎src/quic/application.cc‎

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,13 @@
1919

2020
namespacenode {
2121

22+
using v8::BigInt;
23+
using v8::Boolean;
24+
using v8::DictionaryTemplate;
2225
using v8::Just;
2326
using v8::Local;
2427
using v8::Maybe;
28+
using v8::MaybeLocal;
2529
using v8::Nothing;
2630
using v8::Object;
2731
using v8::Value;
@@ -114,6 +118,44 @@ Maybe<Session::Application_Options> Session::Application_Options::From(
114118
return Just<Application_Options>(options);
115119
}
116120

121+
MaybeLocal<Object> Session::Application_Options::ToObject(
122+
Environment* env) const {
123+
auto& binding_data = BindingData::Get(env);
124+
auto tmpl = binding_data.application_options_template();
125+
staticconstexpr std::string_view names[] = {
126+
"maxHeaderPairs",
127+
"maxHeaderLength",
128+
"maxFieldSectionSize",
129+
"qpackMaxDtableCapacity",
130+
"qpackEncoderMaxDtableCapacity",
131+
"qpackBlockedStreams",
132+
"enableConnectProtocol",
133+
"enableDatagrams",
134+
};
135+
if (tmpl.IsEmpty()) {
136+
tmpl = DictionaryTemplate::New(env->isolate(), names);
137+
binding_data.set_application_options_template(tmpl);
138+
}
139+
MaybeLocal<Value> values[] = {
140+
BigInt::NewFromUnsigned(env->isolate(), max_header_pairs),
141+
BigInt::NewFromUnsigned(env->isolate(), max_header_length),
142+
BigInt::NewFromUnsigned(env->isolate(), max_field_section_size),
143+
BigInt::NewFromUnsigned(env->isolate(), qpack_max_dtable_capacity),
144+
BigInt::NewFromUnsigned(env->isolate(),
145+
qpack_encoder_max_dtable_capacity),
146+
BigInt::NewFromUnsigned(env->isolate(), qpack_blocked_streams),
147+
Boolean::New(env->isolate(), enable_connect_protocol),
148+
Boolean::New(env->isolate(), enable_datagrams),
149+
};
150+
static_assert(std::size(values) == std::size(names));
151+
152+
auto obj = tmpl->NewInstance(env->context(), values);
153+
if (obj->SetPrototypeV2(env->context(), Null(env->isolate())).IsNothing()) {
154+
return {};
155+
}
156+
return obj;
157+
}
158+
117159
// ============================================================================
118160

119161
std::string Session::Application::StreamData::ToString() const {
@@ -655,7 +697,10 @@ class DefaultApplication final : public Session::Application {
655697
// Marked NOLINT because the cpp linter gets confused about this using
656698
// statement not being sorted with the using v8 statements at the top
657699
// of the namespace.
658-
using Application::Application; // NOLINT
700+
DefaultApplication(Session* session, const Options& options)
701+
: Session::Application(session, options), options_(options) {}
702+
703+
const Options& options() constoverride { return options_; }
659704

660705
Session::Application::Type type() constoverride {
661706
return Session::Application::Type::DEFAULT;
@@ -827,6 +872,8 @@ class DefaultApplication final : public Session::Application {
827872
}
828873
}
829874

875+
Options options_;
876+
830877
Stream::Queue stream_queue_;
831878
};
832879

‎src/quic/application.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ class Session::Application : public MemoryRetainer {
3838
Application(Session* session, const Options& options);
3939
DISALLOW_COPY_AND_MOVE(Application)
4040

41+
// Get the active options for this application. These may differ from the
42+
// options passed at construction time since some options can be negotiated.
43+
virtualconst Options& options() const = 0;
44+
4145
// The type of Application, exposed via the session state so JS
4246
// can observe which Application was selected after ALPN negotiation.
4347
// This is used primarily for testing/debugging.

‎src/quic/bindingdata.cc‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,17 @@ void BindingData::set_transport_params_template(
385385

386386
Local<DictionaryTemplate> BindingData::transport_params_template() const {
387387
returnPersistentToLocal::Default(env()->isolate(),
388-
transport_params_template_);
388+
transport_params_template_);
389+
}
390+
391+
voidBindingData::set_application_options_template(
392+
Local<DictionaryTemplate> tmpl) {
393+
application_options_template_.Reset(env()->isolate(), tmpl);
394+
}
395+
396+
Local<DictionaryTemplate> BindingData::application_options_template() const {
397+
returnPersistentToLocal::Default(env()->isolate(),
398+
application_options_template_);
389399
}
390400

391401
#defineV(name, _) \

‎src/quic/bindingdata.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,9 @@ class BindingData final
306306
voidset_transport_params_template(v8::Local<v8::DictionaryTemplate> tmpl);
307307
v8::Local<v8::DictionaryTemplate> transport_params_template() const;
308308

309+
voidset_application_options_template(v8::Local<v8::DictionaryTemplate> tmpl);
310+
v8::Local<v8::DictionaryTemplate> application_options_template() const;
311+
309312
#defineV(name, _) \
310313
void set_##name##_callback(v8::Local<v8::Function> fn); \
311314
v8::Local<v8::Function> name##_callback() const;
@@ -325,6 +328,7 @@ class BindingData final
325328
#undef V
326329

327330
v8::Global<v8::DictionaryTemplate> transport_params_template_;
331+
v8::Global<v8::DictionaryTemplate> application_options_template_;
328332

329333
#defineV(name, _) v8::Global<v8::Function> name##_callback_;
330334
QUIC_JS_CALLBACKS(V)

‎src/quic/http3.cc‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ class Http3ApplicationImpl final : public Session::Application {
157157
session->set_priority_supported();
158158
}
159159

160+
const Options& options() constoverride { return options_; }
161+
160162
Session::Application::Type type() constoverride {
161163
return Session::Application::Type::HTTP3;
162164
}

‎src/quic/session.cc‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ uint64_t MaxDatagramPayload(uint64_t max_frame_size) {
193193
V(SendDatagram, sendDatagram, SIDE_EFFECT) \
194194
V(LocalTransportParams, localTransportParams, NO_SIDE_EFFECT) \
195195
V(RemoteTransportParams, remoteTransportParams, NO_SIDE_EFFECT) \
196+
V(ApplicationOptions, applicationOptions, NO_SIDE_EFFECT)
196197

197198
structSession::State final {
198199
#defineV(_, name, type) type name;
@@ -1195,6 +1196,24 @@ struct Session::Impl final : public MemoryRetainer {
11951196
args.GetReturnValue().Set(obj);
11961197
}
11971198
}
1199+
1200+
JS_METHOD(ApplicationOptions) {
1201+
auto env = Environment::GetCurrent(args);
1202+
Session* session;
1203+
ASSIGN_OR_RETURN_UNWRAP(&session, args.This());
1204+
1205+
Local<Object> obj;
1206+
if (!session->has_application()) {
1207+
// The application has not yet been selected (ALPN negotiation is not
1208+
// yet complete on the server) or the session has been destroyed. In
1209+
// either case, the application options are not available.
1210+
return args.GetReturnValue().SetUndefined();
1211+
}
1212+
auto& options = session->application().options();
1213+
if (options.ToObject(env).ToLocal(&obj)) {
1214+
args.GetReturnValue().Set(obj);
1215+
}
1216+
}
11981217
// Internal ngtcp2 callbacks
11991218

12001219
staticinton_acknowledge_stream_data_offset(ngtcp2_conn* conn,
@@ -2082,6 +2101,10 @@ TLSSession& Session::tls_session() const {
20822101
return *tls_session_;
20832102
}
20842103

2104+
boolSession::has_application() const {
2105+
return !is_destroyed() && impl_->application_ != nullptr;
2106+
}
2107+
20852108
Session::Application& Session::application() const {
20862109
DCHECK(!is_destroyed());
20872110
DCHECK(impl_->application_);

‎src/quic/session.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ class Session final : public AsyncWrap, private SessionTicket::AppData::Source {
9191

9292
std::string ToString() const;
9393

94+
v8::MaybeLocal<v8::Object> ToObject(Environment* env) const;
95+
9496
staticconst Application_Options kDefault;
9597
};
9698

@@ -324,6 +326,7 @@ class Session final : public AsyncWrap, private SessionTicket::AppData::Source {
324326
uint32_tversion() const;
325327
Endpoint& endpoint() const;
326328
TLSSession& tls_session() const;
329+
boolhas_application() const;
327330
Application& application() const;
328331
const Config& config() const;
329332
const Options& options() const;

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Commit 42aa3f6

Browse files
jasnelladuh95
authored andcommitted
quic: add applicationOptions to session
Signed-off-by: James M Snell <jasnell@gmail.com> PR-URL: #63267 Backport-PR-URL: #64675 Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
1 parent 4c00ab9 commit 42aa3f6

11 files changed

Lines changed: 320 additions & 71 deletions

File tree

‎doc/api/quic.md‎

Lines changed: 78 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,18 @@ added: v23.8.0
724724

725725
A `QuicSession` represents the local side of a QUIC connection.
726726

727+
### `session.applicationOptions`
728+
729+
<!-- YAML
730+
added: REPLACEME
731+
-->
732+
733+
* Type: {quic.ApplicationOptions}
734+
735+
The current application-level options for this session. These include settings
736+
that are specific to the negotiated application protocol (e.g. HTTP/3) and may
737+
be negotiated separately from the transport parameters. Read only.
738+
727739
### `session.close([options])`
728740

729741
<!-- YAML
@@ -2218,6 +2230,70 @@ added: v23.8.0
22182230

22192231
## Types
22202232

2233+
### type: `ApplicationOptions`
2234+
2235+
<!-- YAML
2236+
added: REPLACEME
2237+
-->
2238+
2239+
* Type: {Object}
2240+
2241+
The application specific options.
2242+
2243+
#### `applicationOptions.maxHeaderPairs`
2244+
2245+
* Type: {bigint|number}
2246+
2247+
Maximum number of header name-value pairs accepted per header block.
2248+
Headers beyond this limit are silently dropped. **Default:**`128`
2249+
2250+
#### `applicationOptions.maxHeaderLength`
2251+
2252+
* Type: {bigint|number}
2253+
2254+
Maximum total byte length of all header names and values combined per header
2255+
block. Headers that would push the total over this limit are silently
2256+
dropped. **Default:**`8192`
2257+
2258+
#### `applicationOptions.maxFieldSectionSize`
2259+
2260+
* Type: {bigint|number}
2261+
2262+
Maximum size of a compressed header field section (QPACK). `0` means
2263+
unlimited. **Default:**`0`
2264+
2265+
#### `applicationOptions.qpackMaxDTableCapacity`
2266+
2267+
* Type: {bigint|number}
2268+
2269+
QPACK dynamic table capacity in bytes. Set to `0` to disable the dynamic
2270+
table. **Default:**`4096`
2271+
2272+
#### `applicationOptions.qpackEncoderMaxDTableCapacity`
2273+
2274+
* Type: {bigint|number}
2275+
2276+
QPACK encoder maximum dynamic table capacity. **Default:**`4096`
2277+
2278+
#### `applicationOptions.qpackBlockedStreams`
2279+
2280+
* Type: {bigint|number}
2281+
2282+
Maximum number of streams that can e blocked waiting for QPACK dynamic table
2283+
updates. **Default:**`100`
2284+
2285+
#### `applicationOptions.enableConnectProtocol`
2286+
2287+
* Type: {boolean}
2288+
2289+
Enable the extended CONNECT protocol (RFC 9220). **Default:**`false`
2290+
2291+
#### `applicationOptions.enableDatagrams`
2292+
2293+
* Type: {boolean}
2294+
2295+
Enable HTTP/3 datagrams (RFC 9297). **Default:**`false`
2296+
22212297
### Type: `EndpointOptions`
22222298

22232299
<!-- YAML
@@ -2474,30 +2550,9 @@ Default: `'h3'`
24742550
added: REPLACEME
24752551
-->
24762552

2477-
* Type: {Object}
2553+
* Type: {quic.ApplicationOptions}
24782554

2479-
HTTP/3 application-specific options. These only apply when the negotiated
2480-
ALPN selects the HTTP/3 application (`'h3'`).
2481-
2482-
*`maxHeaderPairs` {number} Maximum number of header name-value pairs
2483-
accepted per header block. Headers beyond this limit are silently
2484-
dropped. **Default:**`128`
2485-
*`maxHeaderLength` {number} Maximum total byte length of all header
2486-
names and values combined per header block. Headers that would push
2487-
the total over this limit are silently dropped. **Default:**`8192`
2488-
*`maxFieldSectionSize` {number} Maximum size of a compressed header
2489-
field section (QPACK). `0` means unlimited. **Default:**`0`
2490-
*`qpackMaxDTableCapacity` {number} QPACK dynamic table capacity in
2491-
bytes. Set to `0` to disable the dynamic table. **Default:**`4096`
2492-
*`qpackEncoderMaxDTableCapacity` {number} QPACK encoder maximum
2493-
dynamic table capacity. **Default:**`4096`
2494-
*`qpackBlockedStreams` {number} Maximum number of streams that can
2495-
be blocked waiting for QPACK dynamic table updates.
2496-
**Default:**`100`
2497-
*`enableConnectProtocol` {boolean} Enable the extended CONNECT
2498-
protocol (RFC 9220). **Default:**`false`
2499-
*`enableDatagrams` {boolean} Enable HTTP/3 datagrams (RFC 9297).
2500-
**Default:**`false`
2555+
Application-specific options.
25012556

25022557
```mjs
25032558
const { listen } =awaitimport('node:quic');

‎lib/internal/quic/quic.js‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2678,6 +2678,14 @@ class QuicSession {
26782678
debug('session created');
26792679
}
26802680

2681+
getapplicationOptions(){
2682+
// We don't cache application options because they may be updated by the
2683+
// C++ layer after session creation depending on the behavior of the
2684+
// application.
2685+
if(this.destroyed)returnnull;
2686+
returnthis.#handle.applicationOptions();
2687+
}
2688+
26812689
getlocalTransportParams(){
26822690
if(this.#inner.localTransportParams!==undefined){
26832691
returnthis.#inner.localTransportParams;

‎src/quic/application.cc‎

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,13 @@
1919

2020
namespacenode {
2121

22+
using v8::BigInt;
23+
using v8::Boolean;
24+
using v8::DictionaryTemplate;
2225
using v8::Just;
2326
using v8::Local;
2427
using v8::Maybe;
28+
using v8::MaybeLocal;
2529
using v8::Nothing;
2630
using v8::Object;
2731
using v8::Value;
@@ -114,6 +118,44 @@ Maybe<Session::Application_Options> Session::Application_Options::From(
114118
return Just<Application_Options>(options);
115119
}
116120

121+
MaybeLocal<Object> Session::Application_Options::ToObject(
122+
Environment* env) const {
123+
auto& binding_data = BindingData::Get(env);
124+
auto tmpl = binding_data.application_options_template();
125+
staticconstexpr std::string_view names[] = {
126+
"maxHeaderPairs",
127+
"maxHeaderLength",
128+
"maxFieldSectionSize",
129+
"qpackMaxDtableCapacity",
130+
"qpackEncoderMaxDtableCapacity",
131+
"qpackBlockedStreams",
132+
"enableConnectProtocol",
133+
"enableDatagrams",
134+
};
135+
if (tmpl.IsEmpty()) {
136+
tmpl = DictionaryTemplate::New(env->isolate(), names);
137+
binding_data.set_application_options_template(tmpl);
138+
}
139+
MaybeLocal<Value> values[] = {
140+
BigInt::NewFromUnsigned(env->isolate(), max_header_pairs),
141+
BigInt::NewFromUnsigned(env->isolate(), max_header_length),
142+
BigInt::NewFromUnsigned(env->isolate(), max_field_section_size),
143+
BigInt::NewFromUnsigned(env->isolate(), qpack_max_dtable_capacity),
144+
BigInt::NewFromUnsigned(env->isolate(),
145+
qpack_encoder_max_dtable_capacity),
146+
BigInt::NewFromUnsigned(env->isolate(), qpack_blocked_streams),
147+
Boolean::New(env->isolate(), enable_connect_protocol),
148+
Boolean::New(env->isolate(), enable_datagrams),
149+
};
150+
static_assert(std::size(values) == std::size(names));
151+
152+
auto obj = tmpl->NewInstance(env->context(), values);
153+
if (obj->SetPrototypeV2(env->context(), Null(env->isolate())).IsNothing()) {
154+
return {};
155+
}
156+
return obj;
157+
}
158+
117159
// ============================================================================
118160

119161
std::string Session::Application::StreamData::ToString() const {
@@ -655,7 +697,10 @@ class DefaultApplication final : public Session::Application {
655697
// Marked NOLINT because the cpp linter gets confused about this using
656698
// statement not being sorted with the using v8 statements at the top
657699
// of the namespace.
658-
using Application::Application; // NOLINT
700+
DefaultApplication(Session* session, const Options& options)
701+
: Session::Application(session, options), options_(options) {}
702+
703+
const Options& options() constoverride { return options_; }
659704

660705
Session::Application::Type type() constoverride {
661706
return Session::Application::Type::DEFAULT;
@@ -827,6 +872,8 @@ class DefaultApplication final : public Session::Application {
827872
}
828873
}
829874

875+
Options options_;
876+
830877
Stream::Queue stream_queue_;
831878
};
832879

‎src/quic/application.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ class Session::Application : public MemoryRetainer {
3838
Application(Session* session, const Options& options);
3939
DISALLOW_COPY_AND_MOVE(Application)
4040

41+
// Get the active options for this application. These may differ from the
42+
// options passed at construction time since some options can be negotiated.
43+
virtualconst Options& options() const = 0;
44+
4145
// The type of Application, exposed via the session state so JS
4246
// can observe which Application was selected after ALPN negotiation.
4347
// This is used primarily for testing/debugging.

‎src/quic/bindingdata.cc‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,17 @@ void BindingData::set_transport_params_template(
385385

386386
Local<DictionaryTemplate> BindingData::transport_params_template() const {
387387
returnPersistentToLocal::Default(env()->isolate(),
388-
transport_params_template_);
388+
transport_params_template_);
389+
}
390+
391+
voidBindingData::set_application_options_template(
392+
Local<DictionaryTemplate> tmpl) {
393+
application_options_template_.Reset(env()->isolate(), tmpl);
394+
}
395+
396+
Local<DictionaryTemplate> BindingData::application_options_template() const {
397+
returnPersistentToLocal::Default(env()->isolate(),
398+
application_options_template_);
389399
}
390400

391401
#defineV(name, _) \

‎src/quic/bindingdata.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,9 @@ class BindingData final
306306
voidset_transport_params_template(v8::Local<v8::DictionaryTemplate> tmpl);
307307
v8::Local<v8::DictionaryTemplate> transport_params_template() const;
308308

309+
voidset_application_options_template(v8::Local<v8::DictionaryTemplate> tmpl);
310+
v8::Local<v8::DictionaryTemplate> application_options_template() const;
311+
309312
#defineV(name, _) \
310313
void set_##name##_callback(v8::Local<v8::Function> fn); \
311314
v8::Local<v8::Function> name##_callback() const;
@@ -325,6 +328,7 @@ class BindingData final
325328
#undef V
326329

327330
v8::Global<v8::DictionaryTemplate> transport_params_template_;
331+
v8::Global<v8::DictionaryTemplate> application_options_template_;
328332

329333
#defineV(name, _) v8::Global<v8::Function> name##_callback_;
330334
QUIC_JS_CALLBACKS(V)

‎src/quic/http3.cc‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ class Http3ApplicationImpl final : public Session::Application {
157157
session->set_priority_supported();
158158
}
159159

160+
const Options& options() constoverride { return options_; }
161+
160162
Session::Application::Type type() constoverride {
161163
return Session::Application::Type::HTTP3;
162164
}

‎src/quic/session.cc‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ uint64_t MaxDatagramPayload(uint64_t max_frame_size) {
193193
V(SendDatagram, sendDatagram, SIDE_EFFECT) \
194194
V(LocalTransportParams, localTransportParams, NO_SIDE_EFFECT) \
195195
V(RemoteTransportParams, remoteTransportParams, NO_SIDE_EFFECT) \
196+
V(ApplicationOptions, applicationOptions, NO_SIDE_EFFECT)
196197

197198
structSession::State final {
198199
#defineV(_, name, type) type name;
@@ -1195,6 +1196,24 @@ struct Session::Impl final : public MemoryRetainer {
11951196
args.GetReturnValue().Set(obj);
11961197
}
11971198
}
1199+
1200+
JS_METHOD(ApplicationOptions) {
1201+
auto env = Environment::GetCurrent(args);
1202+
Session* session;
1203+
ASSIGN_OR_RETURN_UNWRAP(&session, args.This());
1204+
1205+
Local<Object> obj;
1206+
if (!session->has_application()) {
1207+
// The application has not yet been selected (ALPN negotiation is not
1208+
// yet complete on the server) or the session has been destroyed. In
1209+
// either case, the application options are not available.
1210+
return args.GetReturnValue().SetUndefined();
1211+
}
1212+
auto& options = session->application().options();
1213+
if (options.ToObject(env).ToLocal(&obj)) {
1214+
args.GetReturnValue().Set(obj);
1215+
}
1216+
}
11981217
// Internal ngtcp2 callbacks
11991218

12001219
staticinton_acknowledge_stream_data_offset(ngtcp2_conn* conn,
@@ -2082,6 +2101,10 @@ TLSSession& Session::tls_session() const {
20822101
return *tls_session_;
20832102
}
20842103

2104+
boolSession::has_application() const {
2105+
return !is_destroyed() && impl_->application_ != nullptr;
2106+
}
2107+
20852108
Session::Application& Session::application() const {
20862109
DCHECK(!is_destroyed());
20872110
DCHECK(impl_->application_);

‎src/quic/session.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ class Session final : public AsyncWrap, private SessionTicket::AppData::Source {
9191

9292
std::string ToString() const;
9393

94+
v8::MaybeLocal<v8::Object> ToObject(Environment* env) const;
95+
9496
staticconst Application_Options kDefault;
9597
};
9698

@@ -324,6 +326,7 @@ class Session final : public AsyncWrap, private SessionTicket::AppData::Source {
324326
uint32_tversion() const;
325327
Endpoint& endpoint() const;
326328
TLSSession& tls_session() const;
329+
boolhas_application() const;
327330
Application& application() const;
328331
const Config& config() const;
329332
const Options& options() const;

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Commit 42aa3f6

Browse files
jasnelladuh95
authored andcommitted
quic: add applicationOptions to session
Signed-off-by: James M Snell <jasnell@gmail.com> PR-URL: #63267 Backport-PR-URL: #64675 Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
1 parent 4c00ab9 commit 42aa3f6

11 files changed

Lines changed: 320 additions & 71 deletions

File tree

‎doc/api/quic.md‎

Lines changed: 78 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,18 @@ added: v23.8.0
724724

725725
A `QuicSession` represents the local side of a QUIC connection.
726726

727+
### `session.applicationOptions`
728+
729+
<!-- YAML
730+
added: REPLACEME
731+
-->
732+
733+
* Type: {quic.ApplicationOptions}
734+
735+
The current application-level options for this session. These include settings
736+
that are specific to the negotiated application protocol (e.g. HTTP/3) and may
737+
be negotiated separately from the transport parameters. Read only.
738+
727739
### `session.close([options])`
728740

729741
<!-- YAML
@@ -2218,6 +2230,70 @@ added: v23.8.0
22182230

22192231
## Types
22202232

2233+
### type: `ApplicationOptions`
2234+
2235+
<!-- YAML
2236+
added: REPLACEME
2237+
-->
2238+
2239+
* Type: {Object}
2240+
2241+
The application specific options.
2242+
2243+
#### `applicationOptions.maxHeaderPairs`
2244+
2245+
* Type: {bigint|number}
2246+
2247+
Maximum number of header name-value pairs accepted per header block.
2248+
Headers beyond this limit are silently dropped. **Default:**`128`
2249+
2250+
#### `applicationOptions.maxHeaderLength`
2251+
2252+
* Type: {bigint|number}
2253+
2254+
Maximum total byte length of all header names and values combined per header
2255+
block. Headers that would push the total over this limit are silently
2256+
dropped. **Default:**`8192`
2257+
2258+
#### `applicationOptions.maxFieldSectionSize`
2259+
2260+
* Type: {bigint|number}
2261+
2262+
Maximum size of a compressed header field section (QPACK). `0` means
2263+
unlimited. **Default:**`0`
2264+
2265+
#### `applicationOptions.qpackMaxDTableCapacity`
2266+
2267+
* Type: {bigint|number}
2268+
2269+
QPACK dynamic table capacity in bytes. Set to `0` to disable the dynamic
2270+
table. **Default:**`4096`
2271+
2272+
#### `applicationOptions.qpackEncoderMaxDTableCapacity`
2273+
2274+
* Type: {bigint|number}
2275+
2276+
QPACK encoder maximum dynamic table capacity. **Default:**`4096`
2277+
2278+
#### `applicationOptions.qpackBlockedStreams`
2279+
2280+
* Type: {bigint|number}
2281+
2282+
Maximum number of streams that can e blocked waiting for QPACK dynamic table
2283+
updates. **Default:**`100`
2284+
2285+
#### `applicationOptions.enableConnectProtocol`
2286+
2287+
* Type: {boolean}
2288+
2289+
Enable the extended CONNECT protocol (RFC 9220). **Default:**`false`
2290+
2291+
#### `applicationOptions.enableDatagrams`
2292+
2293+
* Type: {boolean}
2294+
2295+
Enable HTTP/3 datagrams (RFC 9297). **Default:**`false`
2296+
22212297
### Type: `EndpointOptions`
22222298

22232299
<!-- YAML
@@ -2474,30 +2550,9 @@ Default: `'h3'`
24742550
added: REPLACEME
24752551
-->
24762552

2477-
* Type: {Object}
2553+
* Type: {quic.ApplicationOptions}
24782554

2479-
HTTP/3 application-specific options. These only apply when the negotiated
2480-
ALPN selects the HTTP/3 application (`'h3'`).
2481-
2482-
*`maxHeaderPairs` {number} Maximum number of header name-value pairs
2483-
accepted per header block. Headers beyond this limit are silently
2484-
dropped. **Default:**`128`
2485-
*`maxHeaderLength` {number} Maximum total byte length of all header
2486-
names and values combined per header block. Headers that would push
2487-
the total over this limit are silently dropped. **Default:**`8192`
2488-
*`maxFieldSectionSize` {number} Maximum size of a compressed header
2489-
field section (QPACK). `0` means unlimited. **Default:**`0`
2490-
*`qpackMaxDTableCapacity` {number} QPACK dynamic table capacity in
2491-
bytes. Set to `0` to disable the dynamic table. **Default:**`4096`
2492-
*`qpackEncoderMaxDTableCapacity` {number} QPACK encoder maximum
2493-
dynamic table capacity. **Default:**`4096`
2494-
*`qpackBlockedStreams` {number} Maximum number of streams that can
2495-
be blocked waiting for QPACK dynamic table updates.
2496-
**Default:**`100`
2497-
*`enableConnectProtocol` {boolean} Enable the extended CONNECT
2498-
protocol (RFC 9220). **Default:**`false`
2499-
*`enableDatagrams` {boolean} Enable HTTP/3 datagrams (RFC 9297).
2500-
**Default:**`false`
2555+
Application-specific options.
25012556

25022557
```mjs
25032558
const { listen } =awaitimport('node:quic');

‎lib/internal/quic/quic.js‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2678,6 +2678,14 @@ class QuicSession {
26782678
debug('session created');
26792679
}
26802680

2681+
getapplicationOptions(){
2682+
// We don't cache application options because they may be updated by the
2683+
// C++ layer after session creation depending on the behavior of the
2684+
// application.
2685+
if(this.destroyed)returnnull;
2686+
returnthis.#handle.applicationOptions();
2687+
}
2688+
26812689
getlocalTransportParams(){
26822690
if(this.#inner.localTransportParams!==undefined){
26832691
returnthis.#inner.localTransportParams;

‎src/quic/application.cc‎

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,13 @@
1919

2020
namespacenode {
2121

22+
using v8::BigInt;
23+
using v8::Boolean;
24+
using v8::DictionaryTemplate;
2225
using v8::Just;
2326
using v8::Local;
2427
using v8::Maybe;
28+
using v8::MaybeLocal;
2529
using v8::Nothing;
2630
using v8::Object;
2731
using v8::Value;
@@ -114,6 +118,44 @@ Maybe<Session::Application_Options> Session::Application_Options::From(
114118
return Just<Application_Options>(options);
115119
}
116120

121+
MaybeLocal<Object> Session::Application_Options::ToObject(
122+
Environment* env) const {
123+
auto& binding_data = BindingData::Get(env);
124+
auto tmpl = binding_data.application_options_template();
125+
staticconstexpr std::string_view names[] = {
126+
"maxHeaderPairs",
127+
"maxHeaderLength",
128+
"maxFieldSectionSize",
129+
"qpackMaxDtableCapacity",
130+
"qpackEncoderMaxDtableCapacity",
131+
"qpackBlockedStreams",
132+
"enableConnectProtocol",
133+
"enableDatagrams",
134+
};
135+
if (tmpl.IsEmpty()) {
136+
tmpl = DictionaryTemplate::New(env->isolate(), names);
137+
binding_data.set_application_options_template(tmpl);
138+
}
139+
MaybeLocal<Value> values[] = {
140+
BigInt::NewFromUnsigned(env->isolate(), max_header_pairs),
141+
BigInt::NewFromUnsigned(env->isolate(), max_header_length),
142+
BigInt::NewFromUnsigned(env->isolate(), max_field_section_size),
143+
BigInt::NewFromUnsigned(env->isolate(), qpack_max_dtable_capacity),
144+
BigInt::NewFromUnsigned(env->isolate(),
145+
qpack_encoder_max_dtable_capacity),
146+
BigInt::NewFromUnsigned(env->isolate(), qpack_blocked_streams),
147+
Boolean::New(env->isolate(), enable_connect_protocol),
148+
Boolean::New(env->isolate(), enable_datagrams),
149+
};
150+
static_assert(std::size(values) == std::size(names));
151+
152+
auto obj = tmpl->NewInstance(env->context(), values);
153+
if (obj->SetPrototypeV2(env->context(), Null(env->isolate())).IsNothing()) {
154+
return {};
155+
}
156+
return obj;
157+
}
158+
117159
// ============================================================================
118160

119161
std::string Session::Application::StreamData::ToString() const {
@@ -655,7 +697,10 @@ class DefaultApplication final : public Session::Application {
655697
// Marked NOLINT because the cpp linter gets confused about this using
656698
// statement not being sorted with the using v8 statements at the top
657699
// of the namespace.
658-
using Application::Application; // NOLINT
700+
DefaultApplication(Session* session, const Options& options)
701+
: Session::Application(session, options), options_(options) {}
702+
703+
const Options& options() constoverride { return options_; }
659704

660705
Session::Application::Type type() constoverride {
661706
return Session::Application::Type::DEFAULT;
@@ -827,6 +872,8 @@ class DefaultApplication final : public Session::Application {
827872
}
828873
}
829874

875+
Options options_;
876+
830877
Stream::Queue stream_queue_;
831878
};
832879

‎src/quic/application.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ class Session::Application : public MemoryRetainer {
3838
Application(Session* session, const Options& options);
3939
DISALLOW_COPY_AND_MOVE(Application)
4040

41+
// Get the active options for this application. These may differ from the
42+
// options passed at construction time since some options can be negotiated.
43+
virtualconst Options& options() const = 0;
44+
4145
// The type of Application, exposed via the session state so JS
4246
// can observe which Application was selected after ALPN negotiation.
4347
// This is used primarily for testing/debugging.

‎src/quic/bindingdata.cc‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,17 @@ void BindingData::set_transport_params_template(
385385

386386
Local<DictionaryTemplate> BindingData::transport_params_template() const {
387387
returnPersistentToLocal::Default(env()->isolate(),
388-
transport_params_template_);
388+
transport_params_template_);
389+
}
390+
391+
voidBindingData::set_application_options_template(
392+
Local<DictionaryTemplate> tmpl) {
393+
application_options_template_.Reset(env()->isolate(), tmpl);
394+
}
395+
396+
Local<DictionaryTemplate> BindingData::application_options_template() const {
397+
returnPersistentToLocal::Default(env()->isolate(),
398+
application_options_template_);
389399
}
390400

391401
#defineV(name, _) \

‎src/quic/bindingdata.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,9 @@ class BindingData final
306306
voidset_transport_params_template(v8::Local<v8::DictionaryTemplate> tmpl);
307307
v8::Local<v8::DictionaryTemplate> transport_params_template() const;
308308

309+
voidset_application_options_template(v8::Local<v8::DictionaryTemplate> tmpl);
310+
v8::Local<v8::DictionaryTemplate> application_options_template() const;
311+
309312
#defineV(name, _) \
310313
void set_##name##_callback(v8::Local<v8::Function> fn); \
311314
v8::Local<v8::Function> name##_callback() const;
@@ -325,6 +328,7 @@ class BindingData final
325328
#undef V
326329

327330
v8::Global<v8::DictionaryTemplate> transport_params_template_;
331+
v8::Global<v8::DictionaryTemplate> application_options_template_;
328332

329333
#defineV(name, _) v8::Global<v8::Function> name##_callback_;
330334
QUIC_JS_CALLBACKS(V)

‎src/quic/http3.cc‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ class Http3ApplicationImpl final : public Session::Application {
157157
session->set_priority_supported();
158158
}
159159

160+
const Options& options() constoverride { return options_; }
161+
160162
Session::Application::Type type() constoverride {
161163
return Session::Application::Type::HTTP3;
162164
}

‎src/quic/session.cc‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ uint64_t MaxDatagramPayload(uint64_t max_frame_size) {
193193
V(SendDatagram, sendDatagram, SIDE_EFFECT) \
194194
V(LocalTransportParams, localTransportParams, NO_SIDE_EFFECT) \
195195
V(RemoteTransportParams, remoteTransportParams, NO_SIDE_EFFECT) \
196+
V(ApplicationOptions, applicationOptions, NO_SIDE_EFFECT)
196197

197198
structSession::State final {
198199
#defineV(_, name, type) type name;
@@ -1195,6 +1196,24 @@ struct Session::Impl final : public MemoryRetainer {
11951196
args.GetReturnValue().Set(obj);
11961197
}
11971198
}
1199+
1200+
JS_METHOD(ApplicationOptions) {
1201+
auto env = Environment::GetCurrent(args);
1202+
Session* session;
1203+
ASSIGN_OR_RETURN_UNWRAP(&session, args.This());
1204+
1205+
Local<Object> obj;
1206+
if (!session->has_application()) {
1207+
// The application has not yet been selected (ALPN negotiation is not
1208+
// yet complete on the server) or the session has been destroyed. In
1209+
// either case, the application options are not available.
1210+
return args.GetReturnValue().SetUndefined();
1211+
}
1212+
auto& options = session->application().options();
1213+
if (options.ToObject(env).ToLocal(&obj)) {
1214+
args.GetReturnValue().Set(obj);
1215+
}
1216+
}
11981217
// Internal ngtcp2 callbacks
11991218

12001219
staticinton_acknowledge_stream_data_offset(ngtcp2_conn* conn,
@@ -2082,6 +2101,10 @@ TLSSession& Session::tls_session() const {
20822101
return *tls_session_;
20832102
}
20842103

2104+
boolSession::has_application() const {
2105+
return !is_destroyed() && impl_->application_ != nullptr;
2106+
}
2107+
20852108
Session::Application& Session::application() const {
20862109
DCHECK(!is_destroyed());
20872110
DCHECK(impl_->application_);

‎src/quic/session.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ class Session final : public AsyncWrap, private SessionTicket::AppData::Source {
9191

9292
std::string ToString() const;
9393

94+
v8::MaybeLocal<v8::Object> ToObject(Environment* env) const;
95+
9496
staticconst Application_Options kDefault;
9597
};
9698

@@ -324,6 +326,7 @@ class Session final : public AsyncWrap, private SessionTicket::AppData::Source {
324326
uint32_tversion() const;
325327
Endpoint& endpoint() const;
326328
TLSSession& tls_session() const;
329+
boolhas_application() const;
327330
Application& application() const;
328331
const Config& config() const;
329332
const Options& options() const;

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content

Commit 42aa3f6

Browse files
jasnelladuh95
authored andcommitted
quic: add applicationOptions to session
Signed-off-by: James M Snell <jasnell@gmail.com> PR-URL: #63267 Backport-PR-URL: #64675 Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
1 parent 4c00ab9 commit 42aa3f6

11 files changed

Lines changed: 320 additions & 71 deletions

File tree

‎doc/api/quic.md‎

Lines changed: 78 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,18 @@ added: v23.8.0
724724

725725
A `QuicSession` represents the local side of a QUIC connection.
726726

727+
### `session.applicationOptions`
728+
729+
<!-- YAML
730+
added: REPLACEME
731+
-->
732+
733+
* Type: {quic.ApplicationOptions}
734+
735+
The current application-level options for this session. These include settings
736+
that are specific to the negotiated application protocol (e.g. HTTP/3) and may
737+
be negotiated separately from the transport parameters. Read only.
738+
727739
### `session.close([options])`
728740

729741
<!-- YAML
@@ -2218,6 +2230,70 @@ added: v23.8.0
22182230

22192231
## Types
22202232

2233+
### type: `ApplicationOptions`
2234+
2235+
<!-- YAML
2236+
added: REPLACEME
2237+
-->
2238+
2239+
* Type: {Object}
2240+
2241+
The application specific options.
2242+
2243+
#### `applicationOptions.maxHeaderPairs`
2244+
2245+
* Type: {bigint|number}
2246+
2247+
Maximum number of header name-value pairs accepted per header block.
2248+
Headers beyond this limit are silently dropped. **Default:**`128`
2249+
2250+
#### `applicationOptions.maxHeaderLength`
2251+
2252+
* Type: {bigint|number}
2253+
2254+
Maximum total byte length of all header names and values combined per header
2255+
block. Headers that would push the total over this limit are silently
2256+
dropped. **Default:**`8192`
2257+
2258+
#### `applicationOptions.maxFieldSectionSize`
2259+
2260+
* Type: {bigint|number}
2261+
2262+
Maximum size of a compressed header field section (QPACK). `0` means
2263+
unlimited. **Default:**`0`
2264+
2265+
#### `applicationOptions.qpackMaxDTableCapacity`
2266+
2267+
* Type: {bigint|number}
2268+
2269+
QPACK dynamic table capacity in bytes. Set to `0` to disable the dynamic
2270+
table. **Default:**`4096`
2271+
2272+
#### `applicationOptions.qpackEncoderMaxDTableCapacity`
2273+
2274+
* Type: {bigint|number}
2275+
2276+
QPACK encoder maximum dynamic table capacity. **Default:**`4096`
2277+
2278+
#### `applicationOptions.qpackBlockedStreams`
2279+
2280+
* Type: {bigint|number}
2281+
2282+
Maximum number of streams that can e blocked waiting for QPACK dynamic table
2283+
updates. **Default:**`100`
2284+
2285+
#### `applicationOptions.enableConnectProtocol`
2286+
2287+
* Type: {boolean}
2288+
2289+
Enable the extended CONNECT protocol (RFC 9220). **Default:**`false`
2290+
2291+
#### `applicationOptions.enableDatagrams`
2292+
2293+
* Type: {boolean}
2294+
2295+
Enable HTTP/3 datagrams (RFC 9297). **Default:**`false`
2296+
22212297
### Type: `EndpointOptions`
22222298

22232299
<!-- YAML
@@ -2474,30 +2550,9 @@ Default: `'h3'`
24742550
added: REPLACEME
24752551
-->
24762552

2477-
* Type: {Object}
2553+
* Type: {quic.ApplicationOptions}
24782554

2479-
HTTP/3 application-specific options. These only apply when the negotiated
2480-
ALPN selects the HTTP/3 application (`'h3'`).
2481-
2482-
*`maxHeaderPairs` {number} Maximum number of header name-value pairs
2483-
accepted per header block. Headers beyond this limit are silently
2484-
dropped. **Default:**`128`
2485-
*`maxHeaderLength` {number} Maximum total byte length of all header
2486-
names and values combined per header block. Headers that would push
2487-
the total over this limit are silently dropped. **Default:**`8192`
2488-
*`maxFieldSectionSize` {number} Maximum size of a compressed header
2489-
field section (QPACK). `0` means unlimited. **Default:**`0`
2490-
*`qpackMaxDTableCapacity` {number} QPACK dynamic table capacity in
2491-
bytes. Set to `0` to disable the dynamic table. **Default:**`4096`
2492-
*`qpackEncoderMaxDTableCapacity` {number} QPACK encoder maximum
2493-
dynamic table capacity. **Default:**`4096`
2494-
*`qpackBlockedStreams` {number} Maximum number of streams that can
2495-
be blocked waiting for QPACK dynamic table updates.
2496-
**Default:**`100`
2497-
*`enableConnectProtocol` {boolean} Enable the extended CONNECT
2498-
protocol (RFC 9220). **Default:**`false`
2499-
*`enableDatagrams` {boolean} Enable HTTP/3 datagrams (RFC 9297).
2500-
**Default:**`false`
2555+
Application-specific options.
25012556

25022557
```mjs
25032558
const { listen } =awaitimport('node:quic');

‎lib/internal/quic/quic.js‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2678,6 +2678,14 @@ class QuicSession {
26782678
debug('session created');
26792679
}
26802680

2681+
getapplicationOptions(){
2682+
// We don't cache application options because they may be updated by the
2683+
// C++ layer after session creation depending on the behavior of the
2684+
// application.
2685+
if(this.destroyed)returnnull;
2686+
returnthis.#handle.applicationOptions();
2687+
}
2688+
26812689
getlocalTransportParams(){
26822690
if(this.#inner.localTransportParams!==undefined){
26832691
returnthis.#inner.localTransportParams;

‎src/quic/application.cc‎

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,13 @@
1919

2020
namespacenode {
2121

22+
using v8::BigInt;
23+
using v8::Boolean;
24+
using v8::DictionaryTemplate;
2225
using v8::Just;
2326
using v8::Local;
2427
using v8::Maybe;
28+
using v8::MaybeLocal;
2529
using v8::Nothing;
2630
using v8::Object;
2731
using v8::Value;
@@ -114,6 +118,44 @@ Maybe<Session::Application_Options> Session::Application_Options::From(
114118
return Just<Application_Options>(options);
115119
}
116120

121+
MaybeLocal<Object> Session::Application_Options::ToObject(
122+
Environment* env) const {
123+
auto& binding_data = BindingData::Get(env);
124+
auto tmpl = binding_data.application_options_template();
125+
staticconstexpr std::string_view names[] = {
126+
"maxHeaderPairs",
127+
"maxHeaderLength",
128+
"maxFieldSectionSize",
129+
"qpackMaxDtableCapacity",
130+
"qpackEncoderMaxDtableCapacity",
131+
"qpackBlockedStreams",
132+
"enableConnectProtocol",
133+
"enableDatagrams",
134+
};
135+
if (tmpl.IsEmpty()) {
136+
tmpl = DictionaryTemplate::New(env->isolate(), names);
137+
binding_data.set_application_options_template(tmpl);
138+
}
139+
MaybeLocal<Value> values[] = {
140+
BigInt::NewFromUnsigned(env->isolate(), max_header_pairs),
141+
BigInt::NewFromUnsigned(env->isolate(), max_header_length),
142+
BigInt::NewFromUnsigned(env->isolate(), max_field_section_size),
143+
BigInt::NewFromUnsigned(env->isolate(), qpack_max_dtable_capacity),
144+
BigInt::NewFromUnsigned(env->isolate(),
145+
qpack_encoder_max_dtable_capacity),
146+
BigInt::NewFromUnsigned(env->isolate(), qpack_blocked_streams),
147+
Boolean::New(env->isolate(), enable_connect_protocol),
148+
Boolean::New(env->isolate(), enable_datagrams),
149+
};
150+
static_assert(std::size(values) == std::size(names));
151+
152+
auto obj = tmpl->NewInstance(env->context(), values);
153+
if (obj->SetPrototypeV2(env->context(), Null(env->isolate())).IsNothing()) {
154+
return {};
155+
}
156+
return obj;
157+
}
158+
117159
// ============================================================================
118160

119161
std::string Session::Application::StreamData::ToString() const {
@@ -655,7 +697,10 @@ class DefaultApplication final : public Session::Application {
655697
// Marked NOLINT because the cpp linter gets confused about this using
656698
// statement not being sorted with the using v8 statements at the top
657699
// of the namespace.
658-
using Application::Application; // NOLINT
700+
DefaultApplication(Session* session, const Options& options)
701+
: Session::Application(session, options), options_(options) {}
702+
703+
const Options& options() constoverride { return options_; }
659704

660705
Session::Application::Type type() constoverride {
661706
return Session::Application::Type::DEFAULT;
@@ -827,6 +872,8 @@ class DefaultApplication final : public Session::Application {
827872
}
828873
}
829874

875+
Options options_;
876+
830877
Stream::Queue stream_queue_;
831878
};
832879

‎src/quic/application.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ class Session::Application : public MemoryRetainer {
3838
Application(Session* session, const Options& options);
3939
DISALLOW_COPY_AND_MOVE(Application)
4040

41+
// Get the active options for this application. These may differ from the
42+
// options passed at construction time since some options can be negotiated.
43+
virtualconst Options& options() const = 0;
44+
4145
// The type of Application, exposed via the session state so JS
4246
// can observe which Application was selected after ALPN negotiation.
4347
// This is used primarily for testing/debugging.

‎src/quic/bindingdata.cc‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,17 @@ void BindingData::set_transport_params_template(
385385

386386
Local<DictionaryTemplate> BindingData::transport_params_template() const {
387387
returnPersistentToLocal::Default(env()->isolate(),
388-
transport_params_template_);
388+
transport_params_template_);
389+
}
390+
391+
voidBindingData::set_application_options_template(
392+
Local<DictionaryTemplate> tmpl) {
393+
application_options_template_.Reset(env()->isolate(), tmpl);
394+
}
395+
396+
Local<DictionaryTemplate> BindingData::application_options_template() const {
397+
returnPersistentToLocal::Default(env()->isolate(),
398+
application_options_template_);
389399
}
390400

391401
#defineV(name, _) \

‎src/quic/bindingdata.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,9 @@ class BindingData final
306306
voidset_transport_params_template(v8::Local<v8::DictionaryTemplate> tmpl);
307307
v8::Local<v8::DictionaryTemplate> transport_params_template() const;
308308

309+
voidset_application_options_template(v8::Local<v8::DictionaryTemplate> tmpl);
310+
v8::Local<v8::DictionaryTemplate> application_options_template() const;
311+
309312
#defineV(name, _) \
310313
void set_##name##_callback(v8::Local<v8::Function> fn); \
311314
v8::Local<v8::Function> name##_callback() const;
@@ -325,6 +328,7 @@ class BindingData final
325328
#undef V
326329

327330
v8::Global<v8::DictionaryTemplate> transport_params_template_;
331+
v8::Global<v8::DictionaryTemplate> application_options_template_;
328332

329333
#defineV(name, _) v8::Global<v8::Function> name##_callback_;
330334
QUIC_JS_CALLBACKS(V)

‎src/quic/http3.cc‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ class Http3ApplicationImpl final : public Session::Application {
157157
session->set_priority_supported();
158158
}
159159

160+
const Options& options() constoverride { return options_; }
161+
160162
Session::Application::Type type() constoverride {
161163
return Session::Application::Type::HTTP3;
162164
}

‎src/quic/session.cc‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ uint64_t MaxDatagramPayload(uint64_t max_frame_size) {
193193
V(SendDatagram, sendDatagram, SIDE_EFFECT) \
194194
V(LocalTransportParams, localTransportParams, NO_SIDE_EFFECT) \
195195
V(RemoteTransportParams, remoteTransportParams, NO_SIDE_EFFECT) \
196+
V(ApplicationOptions, applicationOptions, NO_SIDE_EFFECT)
196197

197198
structSession::State final {
198199
#defineV(_, name, type) type name;
@@ -1195,6 +1196,24 @@ struct Session::Impl final : public MemoryRetainer {
11951196
args.GetReturnValue().Set(obj);
11961197
}
11971198
}
1199+
1200+
JS_METHOD(ApplicationOptions) {
1201+
auto env = Environment::GetCurrent(args);
1202+
Session* session;
1203+
ASSIGN_OR_RETURN_UNWRAP(&session, args.This());
1204+
1205+
Local<Object> obj;
1206+
if (!session->has_application()) {
1207+
// The application has not yet been selected (ALPN negotiation is not
1208+
// yet complete on the server) or the session has been destroyed. In
1209+
// either case, the application options are not available.
1210+
return args.GetReturnValue().SetUndefined();
1211+
}
1212+
auto& options = session->application().options();
1213+
if (options.ToObject(env).ToLocal(&obj)) {
1214+
args.GetReturnValue().Set(obj);
1215+
}
1216+
}
11981217
// Internal ngtcp2 callbacks
11991218

12001219
staticinton_acknowledge_stream_data_offset(ngtcp2_conn* conn,
@@ -2082,6 +2101,10 @@ TLSSession& Session::tls_session() const {
20822101
return *tls_session_;
20832102
}
20842103

2104+
boolSession::has_application() const {
2105+
return !is_destroyed() && impl_->application_ != nullptr;
2106+
}
2107+
20852108
Session::Application& Session::application() const {
20862109
DCHECK(!is_destroyed());
20872110
DCHECK(impl_->application_);

‎src/quic/session.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ class Session final : public AsyncWrap, private SessionTicket::AppData::Source {
9191

9292
std::string ToString() const;
9393

94+
v8::MaybeLocal<v8::Object> ToObject(Environment* env) const;
95+
9496
staticconst Application_Options kDefault;
9597
};
9698

@@ -324,6 +326,7 @@ class Session final : public AsyncWrap, private SessionTicket::AppData::Source {
324326
uint32_tversion() const;
325327
Endpoint& endpoint() const;
326328
TLSSession& tls_session() const;
329+
boolhas_application() const;
327330
Application& application() const;
328331
const Config& config() const;
329332
const Options& options() const;

0 commit comments

Comments
 (0)