-
Notifications
You must be signed in to change notification settings - Fork 49
Add support for dynamic backends. #163
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
0c8bc25
Add an alternate error message, which occurs on my machine, at least.
acw bf2675b
Update the Fastly SDK version, and rename `Dictionary` to `ConfigStor…
acw 3805987
Add dynamic backend support.
acw eb48fbd
Fix formatting whoops.
acw 4a8061d
Apply suggestions from code review
acw 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
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,128 @@ | ||
| use { | ||
| crate::common::{Test, TestResult}, | ||
| hyper::{ | ||
| header::{self, HeaderValue}, | ||
| Request, Response, StatusCode, | ||
| }, | ||
| }; | ||
|
|
||
| #[tokio::test(flavor = "multi_thread")] | ||
| async fn upstream_sync() -> TestResult { | ||
| //////////////////////////////////////////////////////////////////////////////////// | ||
| // Setup | ||
| //////////////////////////////////////////////////////////////////////////////////// | ||
|
|
||
| // Set up the test harness | ||
| let test = Test::using_fixture("upstream-dynamic.wasm") | ||
| .backend("origin", "http://127.0.0.1:9000/", None) | ||
| // The "origin" backend simply echos the request body | ||
| .host(9000, |req| { | ||
| let body = req.into_body(); | ||
| Response::new(body) | ||
| }); | ||
|
|
||
| //////////////////////////////////////////////////////////////////////////////////// | ||
| // A simple round-trip echo test to "origin", but with a dynamic backend | ||
| //////////////////////////////////////////////////////////////////////////////////// | ||
|
|
||
| let resp = test | ||
| .against( | ||
| Request::post("http://localhost/") | ||
| .header("Dynamic-Backend", "127.0.0.1:9000") | ||
| .body("Hello, Viceroy!") | ||
| .unwrap(), | ||
| ) | ||
| .await; | ||
| assert_eq!(resp.status(), StatusCode::OK); | ||
| assert_eq!( | ||
| resp.into_body().read_into_string().await?, | ||
| "Hello, Viceroy!" | ||
| ); | ||
|
|
||
| //////////////////////////////////////////////////////////////////////////////////// | ||
| // Test that you can still use standard backends without a problem | ||
| //////////////////////////////////////////////////////////////////////////////////// | ||
|
|
||
| let resp = test | ||
| .against( | ||
| Request::post("http://localhost/") | ||
| .header("Static-Backend", "origin") | ||
| .body("Hello, Viceroy!") | ||
| .unwrap(), | ||
| ) | ||
| .await; | ||
| assert_eq!(resp.status(), StatusCode::OK); | ||
| assert_eq!( | ||
| resp.into_body().read_into_string().await?, | ||
| "Hello, Viceroy!" | ||
| ); | ||
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
| #[tokio::test(flavor = "multi_thread")] | ||
| async fn override_host_works() -> TestResult { | ||
| // Set up the test harness | ||
| let test = Test::using_fixture("upstream-dynamic.wasm") | ||
| .backend( | ||
| "override-host", | ||
| "http://127.0.0.1:9000/", | ||
| None, // Some("otherhost.com"), | ||
| ) | ||
| .host(9000, |req| { | ||
| assert_eq!( | ||
| req.headers().get(header::HOST), | ||
| Some(&HeaderValue::from_static("otherhost.com")) | ||
| ); | ||
| Response::new(vec![]) | ||
| }); | ||
|
|
||
| let resp = test | ||
| .via_hyper() | ||
| .against( | ||
| Request::get("http://localhost:7878/override") | ||
| .header("Dynamic-Backend", "127.0.0.1:9000") | ||
| .header("With-Override", "otherhost.com") | ||
| .body("") | ||
| .unwrap(), | ||
| ) | ||
| .await; | ||
|
|
||
| assert_eq!(resp.status(), StatusCode::OK); | ||
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
| #[tokio::test(flavor = "multi_thread")] | ||
| async fn duplication_errors_right() -> TestResult { | ||
| // Set up the test harness | ||
| let test = Test::using_fixture("upstream-dynamic.wasm") | ||
| .backend("static", "http://127.0.0.1:9000/", None) | ||
| .host(9000, |_| Response::new(vec![])); | ||
|
|
||
| let resp = test | ||
| .against( | ||
| Request::get("http://localhost:7878/override") | ||
| .header("Dynamic-Backend", "127.0.0.1:9000") | ||
| .header("Supplementary-Backend", "dynamic-backend") | ||
| .body("") | ||
| .unwrap(), | ||
| ) | ||
| .await; | ||
|
|
||
| assert_eq!(resp.status(), StatusCode::CONFLICT); | ||
|
|
||
| let resp = test | ||
| .against( | ||
| Request::get("http://localhost:7878/override") | ||
| .header("Dynamic-Backend", "127.0.0.1:9000") | ||
| .header("Supplementary-Backend", "static") | ||
| .body("") | ||
| .unwrap(), | ||
| ) | ||
| .await; | ||
|
|
||
| assert_eq!(resp.status(), StatusCode::CONFLICT); | ||
|
|
||
| Ok(()) | ||
| } |
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
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
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.