Skip to content
Open
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
18 changes: 7 additions & 11 deletions crates/trusted-server-adapter-fastly/src/app.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Full `EdgeZero` application wiring for Trusted Server.
//!
//! Registers all routes from the legacy [`crate::route_request`] into a
//! Registers all routes for the Trusted Server into a
//! [`RouterService`]. On successful startup, attaches [`FinalizeResponseMiddleware`]
//! (outermost) and [`AuthMiddleware`] (inner). When startup fails,
//! [`startup_error_router`] returns a bare router without middleware.
Expand Down Expand Up @@ -114,8 +114,8 @@ pub(crate) fn build_state() -> Result<Arc<AppState>, Report<TrustedServerError>>
///
/// When `settings.consent.consent_store` is configured and the named KV store cannot
/// be opened, returns `Err` so the caller can respond with 503 (fail-closed). This
/// matches the legacy `route_request` behavior where a misconfigured consent store
/// makes consent-dependent routes unavailable rather than proceeding without consent.
/// ensures a misconfigured consent store makes consent-dependent routes unavailable
/// rather than proceeding without consent (fail-closed).
///
/// # Errors
///
Expand Down Expand Up @@ -239,11 +239,7 @@ async fn dispatch_fallback(
// Error helper
// ---------------------------------------------------------------------------

/// Convert a [`Report<TrustedServerError>`] into an HTTP [`Response`],
/// mirroring [`crate::http_error_response`] exactly.
///
/// The near-identical function in `main.rs` is intentional: the legacy path
/// uses fastly HTTP types while this path uses `edgezero_core` types.
/// Converts a [`Report<TrustedServerError>`] into an HTTP [`Response`].
pub(crate) fn http_error(report: &Report<TrustedServerError>) -> Response {
let root_error = report.current_context();
log::error!("Error occurred: {:?}", report);
Expand Down Expand Up @@ -676,9 +672,9 @@ mod tests {
#[test]
fn dispatch_head_on_named_get_route_falls_through_to_publisher_fallback() {
// Regression guard: HEAD /first-party/proxy must reach the publisher
// fallback, not return a router-level 405. Legacy route_request proxies
// every (method, path) combination not matched by a specific arm through
// to the publisher origin.
// fallback, not return a router-level 405. The EdgeZero dispatch path
// proxies every (method, path) combination not matched by a specific
// arm through to the publisher origin.
//
// Without a live backend the publisher proxy errors (502/503), but the
// important invariant is that the status is NOT 405.
Expand Down
48 changes: 1 addition & 47 deletions crates/trusted-server-adapter-fastly/src/compat.rs
Original file line number Diff line number Diff line change
@@ -1,42 +1,9 @@
//! Compatibility bridge between `fastly` SDK types and `http` crate types.
//!
//! Contains only the functions used by the legacy `main()` entry point.
//! Relocated from `trusted-server-core` as part of removing all `fastly` crate
//! imports from the core library.

use edgezero_core::body::Body as EdgeBody;
use edgezero_core::http::{Request as HttpRequest, RequestBuilder, Response as HttpResponse, Uri};
use edgezero_core::http::Response as HttpResponse;
use trusted_server_core::http_util::SPOOFABLE_FORWARDED_HEADERS;

fn build_http_request(req: &fastly::Request, body: EdgeBody) -> HttpRequest {
let uri: Uri = req
.get_url_str()
.parse()
.expect("should parse fastly request URL as URI");

let mut builder: RequestBuilder = edgezero_core::http::request_builder()
.method(req.get_method().clone())
.uri(uri);

for (name, value) in req.get_headers() {
builder = builder.header(name.as_str(), value.as_bytes());
}

builder
.body(body)
.expect("should build http request from fastly request")
}

/// Convert an owned `fastly::Request` into an [`HttpRequest`].
///
/// # Panics
///
/// Panics if the Fastly request URL cannot be parsed as an `http::Uri`.
pub(crate) fn from_fastly_request(mut req: fastly::Request) -> HttpRequest {
let body = EdgeBody::from(req.take_body_bytes());
build_http_request(&req, body)
}

/// Convert a `fastly::Response` into an [`HttpResponse`].
pub(crate) fn from_fastly_response(mut resp: fastly::Response) -> HttpResponse {
let status = resp.get_status();
Expand Down Expand Up @@ -71,19 +38,6 @@ pub(crate) fn to_fastly_response(resp: HttpResponse) -> fastly::Response {
fastly_resp
}

/// Convert an [`HttpResponse`] into a `fastly::Response` without a body.
///
/// Use this when the caller will stream the body separately through
/// [`fastly::Response::stream_to_client`].
pub(crate) fn to_fastly_response_skeleton(resp: HttpResponse) -> fastly::Response {
let (parts, _body) = resp.into_parts();
let mut fastly_resp = fastly::Response::from_status(parts.status.as_u16());
for (name, value) in &parts.headers {
fastly_resp.append_header(name.as_str(), value.as_bytes());
}
fastly_resp
}

/// Sanitize forwarded headers on a `fastly::Request`.
///
/// Strips headers that clients can spoof before any request-derived context
Expand Down
19 changes: 0 additions & 19 deletions crates/trusted-server-adapter-fastly/src/error.rs

This file was deleted.

Loading
Loading