Skip to content

Commit 7d93254

Browse files
elliotttJakeChampion
authored andcommitted
Use HttpReq, HttpResp, and HttpBody in more places
1 parent ef502c4 commit 7d93254

File tree

8 files changed

+142
-100
lines changed

8 files changed

+142
-100
lines changed

runtime/js-compute-runtime/builtins/fastly.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -144,15 +144,14 @@ bool Fastly::createFanoutHandoff(JSContext *cx, unsigned argc, JS::Value *vp) {
144144
return false;
145145
}
146146

147-
fastly_response_handle_t response_handle = INVALID_HANDLE;
148-
fastly_error_t err;
149-
if (!fastly_http_resp_new(&response_handle, &err)) {
150-
HANDLE_ERROR(cx, err);
147+
auto response_handle = HttpResp::make();
148+
if (auto *err = response_handle.to_err()) {
149+
HANDLE_ERROR(cx, *err);
151150
return false;
152151
}
153-
fastly_body_handle_t body_handle = INVALID_HANDLE;
154-
if (!fastly_http_body_new(&body_handle, &err)) {
155-
HANDLE_ERROR(cx, err);
152+
auto body_handle = HttpBody::make();
153+
if (auto *err = body_handle.to_err()) {
154+
HANDLE_ERROR(cx, *err);
156155
return false;
157156
}
158157

@@ -181,8 +180,9 @@ bool Fastly::createFanoutHandoff(JSContext *cx, unsigned argc, JS::Value *vp) {
181180
bool is_upstream = true;
182181
bool is_grip_upgrade = true;
183182
JS::RootedObject response(
184-
cx, builtins::Response::create(cx, response_instance, response_handle, body_handle,
185-
is_upstream, is_grip_upgrade, std::move(backend_chars)));
183+
cx, builtins::Response::create(cx, response_instance, response_handle.unwrap(),
184+
body_handle.unwrap(), is_upstream, is_grip_upgrade,
185+
std::move(backend_chars)));
186186
if (!response) {
187187
return false;
188188
}

runtime/js-compute-runtime/builtins/fetch-event.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,12 @@ JSObject *FetchEvent::prepare_downstream_request(JSContext *cx) {
7474
cx, JS_NewObjectWithGivenProto(cx, &Request::class_, Request::proto_obj));
7575
if (!requestInstance)
7676
return nullptr;
77-
return Request::create(cx, requestInstance, INVALID_HANDLE, INVALID_HANDLE, true);
77+
return Request::create(cx, requestInstance, HttpReq{}, HttpBody{}, true);
7878
}
7979

8080
bool FetchEvent::init_downstream_request(JSContext *cx, JS::HandleObject request,
8181
fastly_request_t *req) {
82-
MOZ_ASSERT(Request::request_handle(request) == INVALID_HANDLE);
82+
MOZ_ASSERT(!Request::request_handle(request).is_valid());
8383

8484
fastly_error_t err;
8585

@@ -176,11 +176,11 @@ bool FetchEvent::request_get(JSContext *cx, unsigned argc, JS::Value *vp) {
176176
namespace {
177177

178178
bool start_response(JSContext *cx, JS::HandleObject response_obj, bool streaming) {
179-
fastly_response_handle_t response = Response::response_handle(response_obj);
180-
fastly_body_handle_t body = RequestOrResponse::body_handle(response_obj);
179+
auto response = Response::response_handle(response_obj);
180+
auto body = RequestOrResponse::body_handle(response_obj);
181181

182182
fastly_error_t err;
183-
if (!fastly_http_resp_send_downstream(response, body, streaming, &err)) {
183+
if (!fastly_http_resp_send_downstream(response.handle, body.handle, streaming, &err)) {
184184
HANDLE_ERROR(cx, err);
185185
return false;
186186
}

runtime/js-compute-runtime/builtins/object-store.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,10 +276,10 @@ bool ObjectStore::put(JSContext *cx, unsigned argc, JS::Value *vp) {
276276
JS::RootedObject stream_source(cx,
277277
builtins::NativeStreamSource::get_stream_source(cx, body_obj));
278278
JS::RootedObject source_owner(cx, builtins::NativeStreamSource::owner(stream_source));
279-
fastly_body_handle_t body = RequestOrResponse::body_handle(source_owner);
279+
auto body = RequestOrResponse::body_handle(source_owner);
280280

281281
fastly_error_t err;
282-
if (!fastly_object_store_insert(object_store_handle(self), &key_str, body, &err)) {
282+
if (!fastly_object_store_insert(object_store_handle(self), &key_str, body.handle, &err)) {
283283
HANDLE_ERROR(cx, err);
284284
return ReturnPromiseRejectedWithPendingError(cx, args);
285285
}

0 commit comments

Comments
 (0)