diff --git a/src/workerd/api/http.c++ b/src/workerd/api/http.c++ index ad7c29eb98c..62c9b1fb3bc 100644 --- a/src/workerd/api/http.c++ +++ b/src/workerd/api/http.c++ @@ -1076,8 +1076,6 @@ jsg::Ref Request::constructor( } KJ_IF_SOME(c, initDict.cache) { - JSG_REQUIRE(FeatureFlags::get(js).getCacheOptionEnabled(), Error, kj::str( - "The 'cache' field on 'RequestInitializerDict' is not implemented.")); cacheMode = getCacheModeFromName(c); } @@ -1200,6 +1198,13 @@ kj::Maybe Request::serializeCfBlobJson(jsg::Lock& js) { return cf.serialize(js); } +void RequestInitializerDict::validate() { + if(cache != kj::none) { + JSG_REQUIRE(Worker::Api::current().getFeatureFlags().getCacheOptionEnabled(), Error, kj::str( + "The 'cache' field on 'RequestInitializerDict' is not implemented.")); + } +} + void Request::serialize( jsg::Lock& js, jsg::Serializer& serializer, const jsg::TypeHandler& initDictHandler) { diff --git a/src/workerd/api/http.h b/src/workerd/api/http.h index 37526cabd90..76b2757b381 100644 --- a/src/workerd/api/http.h +++ b/src/workerd/api/http.h @@ -752,6 +752,8 @@ struct RequestInitializerDict { // jsg::Optional priority; // TODO(conform): Might support later? + void validate(); + JSG_STRUCT(method, headers, body, redirect, fetcher, cf, mode, credentials, cache, referrer, referrerPolicy, integrity, signal); JSG_STRUCT_TS_OVERRIDE(RequestInit { diff --git a/src/workerd/jsg/struct.h b/src/workerd/jsg/struct.h index 31482bb470b..77a76b3177a 100644 --- a/src/workerd/jsg/struct.h +++ b/src/workerd/jsg/struct.h @@ -118,10 +118,15 @@ class StructWrapper, kj::_::Indexes(fields).unwrap(static_cast(*this), isolate, context, in)... }; + + if constexpr (requires { t.validate(); }) { + t.validate(); + } + + return t; } void newContext() = delete;