-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
📞 Support the gRPC flag for dynamic backends (#308)
Enabling this flags adds **experimental** support for gRPC origins for compute services. * Add a grpc flag for backends. * Add some ALPN machinery. * A simple test case for the http2 connection. * Comment out the test until the feature is in the released SDK.
- Loading branch information
Showing
8 changed files
with
121 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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 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,39 @@ | ||
//use crate::common::{Test, TestResult}; | ||
//use hyper::http::response; | ||
//use hyper::server::conn::AddrIncoming; | ||
//use hyper::service::{make_service_fn, service_fn}; | ||
//use hyper::{Request, Server, StatusCode}; | ||
//use std::net::SocketAddr; | ||
// | ||
//#[tokio::test(flavor = "multi_thread")] | ||
//async fn grpc_creates_h2_connection() -> TestResult { | ||
// let test = Test::using_fixture("grpc.wasm"); | ||
// let server_addr: SocketAddr = "127.0.0.1:0".parse().expect("localhost parses"); | ||
// let incoming = AddrIncoming::bind(&server_addr).expect("bind"); | ||
// let bound_port = incoming.local_addr().port(); | ||
// | ||
// let service = make_service_fn(|_| async move { | ||
// Ok::<_, std::io::Error>(service_fn(move |_req| async { | ||
// response::Builder::new() | ||
// .status(200) | ||
// .body("Hello!".to_string()) | ||
// })) | ||
// }); | ||
// | ||
// let server = Server::builder(incoming).http2_only(true).serve(service); | ||
// tokio::spawn(server); | ||
// | ||
// let resp = test | ||
// .against( | ||
// Request::post("/") | ||
// .header("port", bound_port) | ||
// .body("Hello, Viceroy!") | ||
// .unwrap(), | ||
// ) | ||
// .await; | ||
// assert_eq!(resp.status(), StatusCode::OK); | ||
// assert_eq!(resp.into_body().read_into_string().await?, "Hello!"); | ||
// | ||
// Ok(()) | ||
//} | ||
// |
This file contains 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 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 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 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 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 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,27 @@ | ||
use fastly::{Backend, Error, Request}; | ||
//use fastly::experimental::GrpcBackend; | ||
use std::str::FromStr; | ||
|
||
/// Pass everything from the downstream request through to the backend, then pass everything back | ||
/// from the upstream request to the downstream response. | ||
fn main() -> Result<(), Error> { | ||
let client_req = Request::from_client(); | ||
let Some(port_str) = client_req.get_header_str("Port") else { | ||
panic!("Couldn't find out what port to use!"); | ||
}; | ||
let port = u16::from_str(port_str).unwrap(); | ||
|
||
let backend = Backend::builder("grpc-backend", format!("localhost:{}", port)) | ||
// .for_grpc(true) | ||
.finish() | ||
.expect("can build backend"); | ||
|
||
Request::get("http://localhost/") | ||
.with_header("header", "is-a-thing") | ||
.with_body("hello") | ||
.send(backend) | ||
.unwrap() | ||
.send_to_client(); | ||
|
||
Ok(()) | ||
} |