Skip to content

Commit

Permalink
add on_behalf_of endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
acw committed Nov 7, 2024
1 parent f457b28 commit 8a995ad
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 0 deletions.
5 changes: 5 additions & 0 deletions crates/adapter/src/fastly/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1854,6 +1854,11 @@ pub mod fastly_http_req {

res
}

#[export_name = "fastly_http_req#on_behalf_of"]
pub fn on_behalf_of(_: RequestHandle, _: *const u8, _: usize) -> FastlyStatus {
FastlyStatus::UNKNOWN_ERROR
}
}

pub mod fastly_http_resp {
Expand Down
9 changes: 9 additions & 0 deletions lib/compute-at-edge-abi/cache.witx
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@
(typename $cache_lookup_options
(record
(field $request_headers $request_handle) ;; a full request handle, but used only for its headers
(field $service_id (@witx pointer (@witx char8)))
(field $service_id_len u32)
)
)

(typename $cache_lookup_options_mask
(flags (@witx repr u32)
$reserved
$request_headers
$service_id
)
)

Expand All @@ -29,6 +32,8 @@
(record
(field $request_headers $request_handle) ;; a full request handle, but used only for its headers
(field $replace_strategy $cache_replace_strategy)
(field $service_id (@witx pointer (@witx char8)))
(field $service_id_len u32)
)
)

Expand All @@ -37,6 +42,7 @@
$reserved
$request_headers
$replace_strategy
$service_id
)
)

Expand Down Expand Up @@ -65,6 +71,8 @@
(field $user_metadata_ptr (@witx pointer u8))
(field $user_metadata_len (@witx usize))
(field $edge_max_age_ns $cache_duration_ns)
(field $service_id (@witx pointer (@witx char8)))
(field $service_id_len u32)
)
)

Expand All @@ -80,6 +88,7 @@
$user_metadata
$sensitive_data
$edge_max_age_ns
$service_id
)
)

Expand Down
8 changes: 8 additions & 0 deletions lib/compute-at-edge-abi/compute-at-edge.witx
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,14 @@
(param $buf_len (@witx usize))
(result $err (expected $num_bytes (error $fastly_status)))
)

;;; Instead of having this request cache in this service's space, use the
;;; cache of the named service
(@interface func (export "on_behalf_of")
(param $req $request_handle)
(param $service string)
(result $err (expected (error $fastly_status)))
)
)

(module $fastly_http_resp
Expand Down
8 changes: 8 additions & 0 deletions lib/src/component/http_req.rs
Original file line number Diff line number Diff line change
Expand Up @@ -901,4 +901,12 @@ impl http_req::Host for ComponentCtx {
too_large => Err(types::Error::BufferLen(too_large.unwrap_or(0))),
}
}

async fn on_behalf_of(
&mut self,
_: http_req::RequestHandle,
_: Vec<u8>,
) -> Result<(), types::Error> {
Err(types::Error::Unsupported)
}
}
11 changes: 11 additions & 0 deletions lib/src/wiggle_abi/req_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1095,4 +1095,15 @@ impl FastlyHttpReq for Session {
}),
}
}

fn on_behalf_of(
&mut self,
_memory: &mut GuestMemory<'_>,
_ds_req: RequestHandle,
_service: GuestPtr<str>,
) -> Result<(), Error> {
Err(Error::Unsupported {
msg: "on_behalf_of is not supported in Viceroy",
})
}
}
5 changes: 5 additions & 0 deletions lib/wit/deps/fastly/compute.wit
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,11 @@ result<pending-request-handle, error>;
info: inspect-config,
max-len: u64
) -> result<string, error>;

on-behalf-of: func(
h: request-handle,
service: list<u8>,
) -> result<_, error>;
}

/*
Expand Down

0 comments on commit 8a995ad

Please sign in to comment.