@@ -1304,6 +1304,29 @@ bool Request::setCacheKey(JSContext *cx, unsigned argc, JS::Value *vp) {
1304
1304
return true ;
1305
1305
}
1306
1306
1307
+ bool Request::setManualFramingHeaders (JSContext *cx, unsigned argc, JS::Value *vp) {
1308
+ METHOD_HEADER (1 )
1309
+
1310
+ bool manualFramingHeaders = JS::ToBoolean (args.get (0 ));
1311
+ JS::SetReservedSlot (self, static_cast <uint32_t >(Slots::ManualFramingHeaders), JS::BooleanValue (manualFramingHeaders));
1312
+ auto handle = request_handle (self);
1313
+ host_api::Result<host_api::Void> res;
1314
+ if (manualFramingHeaders) {
1315
+ res =
1316
+ handle.set_framing_headers_mode (host_api::FramingHeadersMode::ManuallyFromHeaders);
1317
+ } else {
1318
+ res =
1319
+ handle.set_framing_headers_mode (host_api::FramingHeadersMode::Automatic);
1320
+ }
1321
+ if (auto *err = res.to_err ()) {
1322
+ HANDLE_ERROR (cx, *err);
1323
+ return false ;
1324
+ }
1325
+
1326
+ args.rval ().setUndefined ();
1327
+ return true ;
1328
+ }
1329
+
1307
1330
JSString *GET_atom;
1308
1331
1309
1332
bool Request::clone (JSContext *cx, unsigned argc, JS::Value *vp) {
@@ -1325,13 +1348,13 @@ bool Request::clone(JSContext *cx, unsigned argc, JS::Value *vp) {
1325
1348
JS::GetReservedSlot (self, static_cast <uint32_t >(Slots::URL)));
1326
1349
JS::SetReservedSlot (requestInstance, static_cast <uint32_t >(Slots::IsDownstream),
1327
1350
JS::GetReservedSlot (self, static_cast <uint32_t >(Slots::IsDownstream)));
1328
- JS::RootedValue overrideContentLength (
1351
+ JS::RootedValue manualFramingHeaders (
1329
1352
cx,
1330
- JS::GetReservedSlot (self, static_cast <uint32_t >(Slots::FramingHeadersManuallyFromHeaders )));
1353
+ JS::GetReservedSlot (self, static_cast <uint32_t >(Slots::ManualFramingHeaders )));
1331
1354
JS::SetReservedSlot (requestInstance,
1332
- static_cast <uint32_t >(Slots::FramingHeadersManuallyFromHeaders ),
1333
- overrideContentLength );
1334
- if (JS::ToBoolean (overrideContentLength )) {
1355
+ static_cast <uint32_t >(Slots::ManualFramingHeaders ),
1356
+ manualFramingHeaders );
1357
+ if (JS::ToBoolean (manualFramingHeaders )) {
1335
1358
auto res =
1336
1359
request_handle.set_framing_headers_mode (host_api::FramingHeadersMode::ManuallyFromHeaders);
1337
1360
if (auto *err = res.to_err ()) {
@@ -1473,6 +1496,7 @@ const JSFunctionSpec Request::methods[] = {
1473
1496
JS_FN (" text" , Request::bodyAll<RequestOrResponse::BodyReadResult::Text>, 0 , JSPROP_ENUMERATE),
1474
1497
JS_FN (" setCacheOverride" , Request::setCacheOverride, 3 , JSPROP_ENUMERATE),
1475
1498
JS_FN (" setCacheKey" , Request::setCacheKey, 0 , JSPROP_ENUMERATE),
1499
+ JS_FN (" setManualFramingHeaders" , Request::setManualFramingHeaders, 1 , JSPROP_ENUMERATE),
1476
1500
JS_FN (" clone" , Request::clone, 0 , JSPROP_ENUMERATE),
1477
1501
JS_FS_END,
1478
1502
};
@@ -1686,8 +1710,8 @@ JSObject *Request::create(JSContext *cx, JS::HandleObject requestInstance, JS::H
1686
1710
JS::RootedValue backend_val (cx);
1687
1711
JS::RootedValue cache_override (cx);
1688
1712
JS::RootedValue fastly_val (cx);
1689
- JS::RootedValue overrideContentLength (cx);
1690
- bool hasOverrideContentLength ;
1713
+ JS::RootedValue manualFramingHeaders (cx);
1714
+ bool hasmanualFramingHeaders ;
1691
1715
if (init_val.isObject ()) {
1692
1716
JS::RootedObject init (cx, init_val.toObjectOrNull ());
1693
1717
if (!JS_GetProperty (cx, init, " method" , &method_val) ||
@@ -1696,8 +1720,8 @@ JSObject *Request::create(JSContext *cx, JS::HandleObject requestInstance, JS::H
1696
1720
!JS_GetProperty (cx, init, " backend" , &backend_val) ||
1697
1721
!JS_GetProperty (cx, init, " cacheOverride" , &cache_override) ||
1698
1722
!JS_GetProperty (cx, init, " fastly" , &fastly_val) ||
1699
- !JS_HasOwnProperty (cx, init, " overrideContentLength " , &hasOverrideContentLength ) ||
1700
- !JS_GetProperty (cx, init, " overrideContentLength " , &overrideContentLength )) {
1723
+ !JS_HasOwnProperty (cx, init, " manualFramingHeaders " , &hasmanualFramingHeaders ) ||
1724
+ !JS_GetProperty (cx, init, " manualFramingHeaders " , &manualFramingHeaders )) {
1701
1725
return nullptr ;
1702
1726
}
1703
1727
} else if (!init_val.isNullOrUndefined ()) {
@@ -2009,18 +2033,18 @@ JSObject *Request::create(JSContext *cx, JS::HandleObject requestInstance, JS::H
2009
2033
JS::BooleanValue (false ));
2010
2034
}
2011
2035
2012
- if (!hasOverrideContentLength ) {
2036
+ if (!hasmanualFramingHeaders ) {
2013
2037
if (input_request) {
2014
- overrideContentLength .set (JS::GetReservedSlot (
2015
- input_request, static_cast <uint32_t >(Slots::FramingHeadersManuallyFromHeaders )));
2038
+ manualFramingHeaders .set (JS::GetReservedSlot (
2039
+ input_request, static_cast <uint32_t >(Slots::ManualFramingHeaders )));
2016
2040
} else {
2017
- overrideContentLength .setBoolean (false );
2041
+ manualFramingHeaders .setBoolean (false );
2018
2042
}
2019
2043
}
2020
- JS::SetReservedSlot (request, static_cast <uint32_t >(Slots::FramingHeadersManuallyFromHeaders ),
2021
- JS::BooleanValue (JS::ToBoolean (overrideContentLength )));
2044
+ JS::SetReservedSlot (request, static_cast <uint32_t >(Slots::ManualFramingHeaders ),
2045
+ JS::BooleanValue (JS::ToBoolean (manualFramingHeaders )));
2022
2046
2023
- if (JS::ToBoolean (overrideContentLength )) {
2047
+ if (JS::ToBoolean (manualFramingHeaders )) {
2024
2048
auto res =
2025
2049
request_handle.set_framing_headers_mode (host_api::FramingHeadersMode::ManuallyFromHeaders);
2026
2050
if (auto *err = res.to_err ()) {
@@ -2650,6 +2674,28 @@ bool Response::json(JSContext *cx, unsigned argc, JS::Value *vp) {
2650
2674
return true ;
2651
2675
}
2652
2676
2677
+ bool Response::setManualFramingHeaders (JSContext *cx, unsigned argc, JS::Value *vp) {
2678
+ METHOD_HEADER (1 )
2679
+
2680
+ bool manualFramingHeaders = JS::ToBoolean (args.get (0 ));
2681
+ JS::SetReservedSlot (self, static_cast <uint32_t >(Slots::ManualFramingHeaders), JS::BooleanValue (manualFramingHeaders));
2682
+ auto handle = response_handle (self);
2683
+ host_api::Result<host_api::Void> res;
2684
+ if (manualFramingHeaders) {
2685
+ res = handle.set_framing_headers_mode (host_api::FramingHeadersMode::ManuallyFromHeaders);
2686
+ } else {
2687
+ res = handle.set_framing_headers_mode (host_api::FramingHeadersMode::Automatic);
2688
+ }
2689
+ if (auto *err = res.to_err ()) {
2690
+ HANDLE_ERROR (cx, *err);
2691
+ return false ;
2692
+ }
2693
+
2694
+ args.rval ().setUndefined ();
2695
+ return true ;
2696
+ }
2697
+
2698
+
2653
2699
const JSFunctionSpec Response::static_methods[] = {
2654
2700
JS_FN (" redirect" , redirect, 1 , JSPROP_ENUMERATE),
2655
2701
JS_FN (" json" , json, 1 , JSPROP_ENUMERATE),
@@ -2665,6 +2711,7 @@ const JSFunctionSpec Response::methods[] = {
2665
2711
JSPROP_ENUMERATE),
2666
2712
JS_FN (" json" , bodyAll<RequestOrResponse::BodyReadResult::JSON>, 0 , JSPROP_ENUMERATE),
2667
2713
JS_FN (" text" , bodyAll<RequestOrResponse::BodyReadResult::Text>, 0 , JSPROP_ENUMERATE),
2714
+ JS_FN (" setManualFramingHeaders" , Response::setManualFramingHeaders, 1 , JSPROP_ENUMERATE),
2668
2715
JS_FS_END,
2669
2716
};
2670
2717
@@ -2700,8 +2747,8 @@ bool Response::constructor(JSContext *cx, unsigned argc, JS::Value *vp) {
2700
2747
JS::RootedValue statusText_val (cx);
2701
2748
JS::RootedString statusText (cx, JS_GetEmptyString (cx));
2702
2749
JS::RootedValue headers_val (cx);
2703
- bool hasOverrideContentLength ;
2704
- JS::RootedValue overrideContentLength (cx);
2750
+ bool hasmanualFramingHeaders ;
2751
+ JS::RootedValue manualFramingHeaders (cx);
2705
2752
host_api::FramingHeadersMode mode{host_api::FramingHeadersMode::Automatic};
2706
2753
2707
2754
if (init_val.isObject ()) {
@@ -2747,8 +2794,8 @@ bool Response::constructor(JSContext *cx, unsigned argc, JS::Value *vp) {
2747
2794
statusText = JS_NewStringCopyZ (cx, status_text.c_str ());
2748
2795
}
2749
2796
2750
- if (!JS_HasOwnProperty (cx, init, " overrideContentLength " , &hasOverrideContentLength ) ||
2751
- !JS_GetProperty (cx, init, " overrideContentLength " , &overrideContentLength )) {
2797
+ if (!JS_HasOwnProperty (cx, init, " manualFramingHeaders " , &hasmanualFramingHeaders ) ||
2798
+ !JS_GetProperty (cx, init, " manualFramingHeaders " , &manualFramingHeaders )) {
2752
2799
return false ;
2753
2800
}
2754
2801
@@ -2801,20 +2848,20 @@ bool Response::constructor(JSContext *cx, unsigned argc, JS::Value *vp) {
2801
2848
return false ;
2802
2849
}
2803
2850
2804
- if (!hasOverrideContentLength ) {
2851
+ if (!hasmanualFramingHeaders ) {
2805
2852
if (is_instance (init_val)) {
2806
- overrideContentLength .set (
2853
+ manualFramingHeaders .set (
2807
2854
JS::GetReservedSlot (init_val.toObjectOrNull (),
2808
- static_cast <uint32_t >(Slots::FramingHeadersManuallyFromHeaders )));
2855
+ static_cast <uint32_t >(Slots::ManualFramingHeaders )));
2809
2856
} else {
2810
- overrideContentLength .setBoolean (false );
2857
+ manualFramingHeaders .setBoolean (false );
2811
2858
}
2812
2859
}
2813
- JS::SetReservedSlot (response, static_cast <uint32_t >(Slots::FramingHeadersManuallyFromHeaders ),
2814
- JS::BooleanValue (JS::ToBoolean (overrideContentLength )));
2860
+ JS::SetReservedSlot (response, static_cast <uint32_t >(Slots::ManualFramingHeaders ),
2861
+ JS::BooleanValue (JS::ToBoolean (manualFramingHeaders )));
2815
2862
2816
- // `overrideContentLength : true` indicates that we want to set the framing mode manually.
2817
- if (JS::ToBoolean (overrideContentLength )) {
2863
+ // `manualFramingHeaders : true` indicates that we want to set the framing mode manually.
2864
+ if (JS::ToBoolean (manualFramingHeaders )) {
2818
2865
mode = host_api::FramingHeadersMode::ManuallyFromHeaders;
2819
2866
}
2820
2867
if (mode != host_api::FramingHeadersMode::Automatic) {
0 commit comments