-
Notifications
You must be signed in to change notification settings - Fork 8
Remove fastly dependency from trusted-server-core (PR 15) #635
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
prk-Jr
wants to merge
17
commits into
feature/edgezero-pr14-entry-point-dual-path
Choose a base branch
from
feature/edgezero-pr15-remove-fastly-core
base: feature/edgezero-pr14-entry-point-dual-path
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
6c4965b
Add PR15 implementation plan: remove fastly from core crate
prk-Jr f67be31
Move compat conversion fns to adapter, delete core compat.rs
prk-Jr c2e0776
Move geo_from_fastly from core to adapter platform
prk-Jr 25bcf99
Move BackendConfig from core to adapter backend module
prk-Jr 8303b84
Delete dead backend_name_for_url from adapter backend
prk-Jr 76087e4
Delete legacy FastlyConfigStore and FastlySecretStore from core
prk-Jr 7795e69
Remove fastly::kv_store from core consent module
prk-Jr abd1f26
Fix consent KV trait design and formatting
prk-Jr d96dbbe
Move tokio to dev-dependencies in core (test-only usage)
prk-Jr 8f40601
Remove fastly dependency from trusted-server-core
prk-Jr 9a4357c
Remove stale fastly:: references from core doc comments
prk-Jr 46704c0
Apply cargo fmt formatting fixes
prk-Jr 60611fa
Wire consent KV into auction path and remove tokio from core tests
prk-Jr 02639db
Merge feature/edgezero-pr14-entry-point-dual-path into PR15
prk-Jr d8060d3
Address PR15 review findings: diagnostic regression, header dedup, co…
prk-Jr 3a53f33
Resolve PR15 consent and backend review findings
prk-Jr 54d191b
Merge feature/edgezero-pr14-entry-point-dual-path into feature/edgeze…
prk-Jr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,133 @@ | ||
| //! Compatibility bridge between `fastly` SDK types and `http` crate types. | ||
| //! | ||
| //! Contains only the three 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 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 an [`HttpResponse`] into a `fastly::Response`. | ||
| pub(crate) fn to_fastly_response(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()); | ||
| } | ||
|
|
||
| match body { | ||
| EdgeBody::Once(bytes) => { | ||
| if !bytes.is_empty() { | ||
| fastly_resp.set_body(bytes.to_vec()); | ||
| } | ||
| } | ||
| EdgeBody::Stream(_) => { | ||
| log::warn!("streaming body in compat::to_fastly_response; body will be empty"); | ||
| } | ||
| } | ||
|
|
||
| fastly_resp | ||
| } | ||
|
|
||
| /// Sanitize forwarded headers on a `fastly::Request`. | ||
| /// | ||
| /// Strips headers that clients can spoof before any request-derived context | ||
| /// is built or the request is converted to core HTTP types. | ||
| pub(crate) fn sanitize_fastly_forwarded_headers(req: &mut fastly::Request) { | ||
| for &name in SPOOFABLE_FORWARDED_HEADERS { | ||
| if req.get_header(name).is_some() { | ||
| log::debug!("Stripped spoofable header: {name}"); | ||
| req.remove_header(name); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
|
|
||
| #[test] | ||
| fn sanitize_fastly_forwarded_headers_strips_spoofable() { | ||
| let mut req = fastly::Request::get("https://example.com/"); | ||
| req.set_header("forwarded", "for=1.2.3.4"); | ||
| req.set_header("x-forwarded-host", "evil.example.com"); | ||
| req.set_header("x-forwarded-proto", "http"); | ||
| req.set_header("fastly-ssl", "1"); | ||
| req.set_header("host", "example.com"); | ||
|
|
||
| sanitize_fastly_forwarded_headers(&mut req); | ||
|
|
||
| assert!( | ||
| req.get_header("forwarded").is_none(), | ||
| "should strip forwarded" | ||
| ); | ||
| assert!( | ||
| req.get_header("x-forwarded-host").is_none(), | ||
| "should strip x-forwarded-host" | ||
| ); | ||
| assert!( | ||
| req.get_header("x-forwarded-proto").is_none(), | ||
| "should strip x-forwarded-proto" | ||
| ); | ||
| assert!( | ||
| req.get_header("fastly-ssl").is_none(), | ||
| "should strip fastly-ssl" | ||
| ); | ||
| assert!(req.get_header("host").is_some(), "should preserve host"); | ||
| } | ||
|
|
||
| #[test] | ||
| fn to_fastly_response_with_streaming_body_produces_empty_body() { | ||
| use edgezero_core::http::StatusCode; | ||
|
|
||
| let stream = futures::stream::empty::<bytes::Bytes>(); | ||
| let stream_body = EdgeBody::stream(stream); | ||
|
|
||
| let http_resp = edgezero_core::http::response_builder() | ||
| .status(StatusCode::OK) | ||
| .body(stream_body) | ||
| .expect("should build response"); | ||
|
|
||
| let mut fastly_resp = to_fastly_response(http_resp); | ||
|
|
||
| assert_eq!( | ||
| fastly_resp.get_status().as_u16(), | ||
| 200, | ||
| "should preserve status" | ||
| ); | ||
| assert!( | ||
| fastly_resp.take_body_bytes().is_empty(), | ||
| "should produce empty body for streaming response" | ||
| ); | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.