Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ pub(crate) mod bindings {
imports: {
default: tracing,

"fastly:adapter/adapter-backend/register-dynamic-backend": async | tracing,
"fastly:adapter/adapter-http-req/send": async | tracing,
"fastly:adapter/adapter-http-req/send-async": async | tracing,
"fastly:adapter/adapter-http-req/send-async-streaming": async | tracing,
"fastly:adapter/adapter-http-req/send-async-uncached": async | tracing,
"fastly:adapter/adapter-http-req/send-async-uncached-streaming": async | tracing,
"fastly:adapter/adapter-http-req/send-uncached": async | tracing,

"fastly:compute/backend/[constructor]dynamic-backend-options": tracing | trappable,
"fastly:compute/shielding/[constructor]shield-backend-options": tracing | trappable,
"fastly:compute/cache/[constructor]extra-lookup-options": tracing | trappable,
Expand Down Expand Up @@ -111,6 +119,9 @@ pub(crate) mod bindings {
"fastly:adapter/adapter-uap/user-agent": super::adapter::uap::UserAgent,
"fastly:compute/kv-store/entry": super::compute::kv_store::Entry,
"fastly:compute/backend/dynamic-backend-options": super::compute::backend::BackendBuilder,
"fastly:compute/backend/backend": String,
"fastly:compute/erl/rate-counter": String,
"fastly:compute/erl/penalty-box": String,
},

trappable_error_type: {
Expand All @@ -130,6 +141,11 @@ pub fn link_host_functions(linker: &mut component::Linker<ComponentCtx>) -> anyh
}

pub mod adapter;
pub mod backend;
pub mod compute;
pub mod erl;
pub mod handles;
pub mod http_req;
pub mod image_optimizer;
pub mod shielding;
pub mod wasi;
5 changes: 5 additions & 0 deletions src/component/adapter.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
//! Implementations for `fastly:adapter` interfaces.

pub mod abi;
pub mod backend;
pub mod cache;
pub mod erl;
pub mod http_cache;
pub mod http_downstream;
pub mod http_req;
pub mod image_optimizer;
pub mod shielding;
pub mod uap;
6 changes: 6 additions & 0 deletions src/component/adapter/abi.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
use crate::component::bindings::fastly::adapter::adapter_abi;
use crate::linking::ComponentCtx;

impl adapter_abi::Host for ComponentCtx {
fn init(&mut self) {}
}
117 changes: 117 additions & 0 deletions src/component/adapter/backend.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
use crate::component::{
bindings::fastly::adapter::adapter_backend,
bindings::fastly::compute::{http_types, types},
};
use crate::linking::ComponentCtx;
use wasmtime::component::Resource;

impl adapter_backend::Host for ComponentCtx {
async fn register_dynamic_backend(
&mut self,
name: String,
origin: String,
config_handle: Resource<adapter_backend::DynamicBackendOptions>,
) -> Result<(), types::Error> {
// Discard the handle for this API, as we register the backend
// in a namespace that other adapter APIs access by name.
crate::component::backend::register_dynamic_backend(
&mut self.session,
&mut self.wasi_table,
name,
origin,
config_handle,
)
.await
.map(|_| ())
}

fn exists(&mut self, name: String) -> Result<bool, types::Error> {
Ok(crate::component::backend::exists(&mut self.session, &name))
}

fn is_healthy(&mut self, name: String) -> Result<adapter_backend::BackendHealth, types::Error> {
crate::component::backend::is_healthy(&mut self.session, &name)
}

fn is_dynamic(&mut self, name: String) -> Result<bool, types::Error> {
crate::component::backend::is_dynamic(&mut self.session, &name)
}

fn get_host(&mut self, name: String, max_len: u64) -> Result<String, types::Error> {
crate::component::backend::get_host(&mut self.session, &name, max_len)
}

fn get_override_host(
&mut self,
name: String,
max_len: u64,
) -> Result<Option<Vec<u8>>, types::Error> {
crate::component::backend::get_override_host(&mut self.session, &name, max_len)
}

fn get_port(&mut self, backend: String) -> Result<u16, types::Error> {
crate::component::backend::get_port(&mut self.session, &backend)
}

fn get_connect_timeout_ms(&mut self, backend: String) -> Result<u32, types::Error> {
crate::component::backend::get_connect_timeout_ms(&mut self.session, &backend)
}

fn get_first_byte_timeout_ms(&mut self, backend: String) -> Result<u32, types::Error> {
crate::component::backend::get_first_byte_timeout_ms(&mut self.session, &backend)
}

fn get_between_bytes_timeout_ms(&mut self, backend: String) -> Result<u32, types::Error> {
crate::component::backend::get_between_bytes_timeout_ms(&mut self.session, &backend)
}

fn get_http_keepalive_time(
&mut self,
backend: String,
) -> Result<adapter_backend::TimeoutMs, types::Error> {
crate::component::backend::get_http_keepalive_time(&mut self.session, &backend)
}

fn get_tcp_keepalive_enable(&mut self, backend: String) -> Result<bool, types::Error> {
crate::component::backend::get_tcp_keepalive_enable(&mut self.session, &backend)
}

fn get_tcp_keepalive_interval(
&mut self,
backend: String,
) -> Result<adapter_backend::TimeoutSecs, types::Error> {
crate::component::backend::get_tcp_keepalive_interval(&mut self.session, &backend)
}

fn get_tcp_keepalive_probes(
&mut self,
backend: String,
) -> Result<adapter_backend::ProbeCount, types::Error> {
crate::component::backend::get_tcp_keepalive_probes(&mut self.session, &backend)
}

fn get_tcp_keepalive_time(
&mut self,
backend: String,
) -> Result<adapter_backend::TimeoutSecs, types::Error> {
crate::component::backend::get_tcp_keepalive_time(&mut self.session, &backend)
}

fn is_tls(&mut self, backend: String) -> Result<bool, types::Error> {
crate::component::backend::is_tls(&mut self.session, &backend)
}

fn get_tls_min_version(
&mut self,
backend: String,
) -> Result<Option<http_types::TlsVersion>, types::Error> {
crate::component::backend::get_tls_min_version(&mut self.session, &backend)
}

fn get_tls_max_version(
&mut self,
backend: String,
) -> Result<Option<http_types::TlsVersion>, types::Error> {
crate::component::backend::get_tls_max_version(&mut self.session, &backend)
}
}
61 changes: 61 additions & 0 deletions src/component/adapter/erl.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
use crate::component::{bindings::fastly::adapter::adapter_erl, bindings::fastly::compute::types};
use crate::linking::ComponentCtx;

impl adapter_erl::Host for ComponentCtx {
fn check_rate(
&mut self,
rc: String,
entry: String,
delta: u32,
window: u32,
limit: u32,
pb: String,
ttl: u32,
) -> Result<bool, types::Error> {
crate::component::erl::check_rate(
&mut self.session,
&rc,
entry,
delta,
window,
limit,
&pb,
ttl,
)
}

fn ratecounter_increment(
&mut self,
rc: String,
entry: String,
delta: u32,
) -> Result<(), types::Error> {
crate::component::erl::ratecounter_increment(&mut self.session, &rc, entry, delta)
}

fn ratecounter_lookup_rate(
&mut self,
rc: String,
entry: String,
window: u32,
) -> Result<u32, types::Error> {
crate::component::erl::ratecounter_lookup_rate(&mut self.session, &rc, entry, window)
}

fn ratecounter_lookup_count(
&mut self,
rc: String,
entry: String,
duration: u32,
) -> Result<u32, types::Error> {
crate::component::erl::ratecounter_lookup_count(&mut self.session, &rc, entry, duration)
}

fn penaltybox_add(&mut self, pb: String, entry: String, ttl: u32) -> Result<(), types::Error> {
crate::component::erl::penaltybox_add(&mut self.session, &pb, entry, ttl)
}

fn penaltybox_has(&mut self, pb: String, entry: String) -> Result<bool, types::Error> {
crate::component::erl::penaltybox_has(&mut self.session, &pb, entry)
}
}
22 changes: 21 additions & 1 deletion src/component/adapter/http_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,31 @@ impl adapter_http_cache::Host for ComponentCtx {
fn lookup(
&mut self,
_req_handle: Resource<http_cache::Request>,
_options: http_cache::LookupOptions,
_options: adapter_http_cache::LookupOptions,
) -> Result<Resource<http_cache::Entry>, types::Error> {
Err(Error::Unsupported {
msg: "HTTP Cache API primitives not yet supported",
}
.into())
}

fn transaction_lookup(
&mut self,
_req_handle: Resource<http_cache::Request>,
_options: adapter_http_cache::LookupOptions,
) -> Result<Resource<http_cache::Entry>, types::Error> {
Err(Error::Unsupported {
msg: "HTTP Cache API primitives not yet supported",
}
.into())
}
}

impl adapter_http_cache::HostExtraLookupOptions for ComponentCtx {
fn drop(
&mut self,
_h: Resource<adapter_http_cache::ExtraLookupOptions>,
) -> wasmtime::Result<()> {
Ok(())
}
}
92 changes: 89 additions & 3 deletions src/component/adapter/http_req.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use {
crate::component::bindings::{
fastly::adapter::adapter_http_req,
fastly::compute::http_downstream::Host as HttpDownstream,
fastly::compute::{http_req, types},
fastly::compute::{http_body, http_req, http_resp, types},
},
crate::{
error::Error,
Expand All @@ -28,14 +28,14 @@ impl adapter_http_req::Host for ComponentCtx {
HttpDownstream::fastly_key_is_valid(self, self.ds_req_handle())
}

fn redirect_to_websocket_proxy_deprecated(
fn redirect_to_websocket_proxy_norequest(
&mut self,
_backend: String,
) -> Result<(), types::Error> {
Err(Error::NotAvailable("Redirect to WebSocket proxy").into())
}

fn redirect_to_grip_proxy_deprecated(
fn redirect_to_grip_proxy_norequest(
&mut self,
backend_name: String,
) -> Result<(), types::Error> {
Expand Down Expand Up @@ -155,4 +155,90 @@ impl adapter_http_req::Host for ComponentCtx {
}
.into())
}

fn redirect_to_websocket_proxy(
&mut self,
handle: Resource<http_req::Request>,
backend: String,
) -> Result<(), types::Error> {
crate::component::http_req::redirect_to_websocket_proxy(&mut self.session, handle, &backend)
}

fn redirect_to_grip_proxy(
&mut self,
req_handle: Resource<http_req::Request>,
backend_name: String,
) -> Result<(), types::Error> {
crate::component::http_req::redirect_to_grip_proxy(
&mut self.session,
req_handle,
&backend_name,
)
}

fn upgrade_websocket(&mut self, backend: String) -> Result<(), types::Error> {
crate::component::http_req::upgrade_websocket(&mut self.session, &backend)
}

async fn send(
&mut self,
h: Resource<http_req::Request>,
b: Resource<http_body::Body>,
backend_name: String,
) -> Result<http_resp::ResponseWithBody, http_req::ErrorWithDetail> {
crate::component::http_req::send(&mut self.session, h, b, &backend_name).await
}

async fn send_uncached(
&mut self,
h: Resource<http_req::Request>,
b: Resource<http_body::Body>,
backend_name: String,
) -> Result<http_resp::ResponseWithBody, http_req::ErrorWithDetail> {
crate::component::http_req::send_uncached(&mut self.session, h, b, &backend_name).await
}

async fn send_async(
&mut self,
h: Resource<http_req::Request>,
b: Resource<http_body::Body>,
backend_name: String,
) -> Result<Resource<http_req::PendingRequest>, types::Error> {
crate::component::http_req::send_async(&mut self.session, h, b, &backend_name).await
}

async fn send_async_uncached(
&mut self,
h: Resource<http_req::Request>,
b: Resource<http_body::Body>,
backend_name: String,
) -> Result<Resource<http_req::PendingRequest>, types::Error> {
crate::component::http_req::send_async_uncached(&mut self.session, h, b, &backend_name)
.await
}

async fn send_async_uncached_streaming(
&mut self,
h: Resource<http_req::Request>,
b: Resource<http_body::Body>,
backend_name: String,
) -> Result<Resource<http_req::PendingRequest>, types::Error> {
crate::component::http_req::send_async_uncached_streaming(
&mut self.session,
h,
b,
&backend_name,
)
.await
}

async fn send_async_streaming(
&mut self,
h: Resource<http_req::Request>,
b: Resource<http_body::Body>,
backend_name: String,
) -> Result<Resource<http_req::PendingRequest>, types::Error> {
crate::component::http_req::send_async_streaming(&mut self.session, h, b, &backend_name)
.await
}
}
Loading
Loading