Skip to content
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

multi layer proxy example. #3628

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 10 additions & 14 deletions Cargo.toml
Expand Up @@ -50,16 +50,7 @@ spmc = "0.3"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
tokio = { version = "1", features = [
"fs",
"macros",
"net",
"io-std",
"io-util",
"rt",
"rt-multi-thread", # so examples can use #[tokio::main]
"sync",
"time",
"test-util",
"full"
] }
tokio-test = "0.4"
tokio-util = "0.7.10"
Expand All @@ -70,10 +61,10 @@ default = []

# Easily turn it all on
full = [
"client",
"http1",
"http2",
"server",
"client",
"http1",
"http2",
"server",
]

# HTTP versions
Expand Down Expand Up @@ -108,6 +99,11 @@ incremental = false
codegen-units = 1
incremental = false

[[example]]
name = "multi_layer_proxy"
path = "examples/multi_layer_proxy.rs"
required-features = ["full"]

[[example]]
name = "client"
path = "examples/client.rs"
Expand Down
41 changes: 29 additions & 12 deletions examples/README.md
@@ -1,10 +1,11 @@
# Examples of using hyper

These examples show how to do common tasks using `hyper`. You may also find the [Guides](https://hyper.rs/guides/1/) helpful.
These examples show how to do common tasks using `hyper`. You may also find the [Guides](https://hyper.rs/guides/1/)
helpful.

If you checkout this repository, you can run any of the examples with the command:

`cargo run --example {example_name} --features="full"`
`cargo run --example {example_name} --features="full"`

### Dependencies

Expand All @@ -28,9 +29,11 @@ futures-util = { version = "0.3", default-features = false }

### Clients

* [`client`](client.rs) - A simple CLI http client that requests the url passed in parameters and outputs the response content and details to the stdout, reading content chunk-by-chunk.
* [`client`](client.rs) - A simple CLI http client that requests the url passed in parameters and outputs the response
content and details to the stdout, reading content chunk-by-chunk.

* [`client_json`](client_json.rs) - A simple program that GETs some json, reads the body asynchronously, parses it with serde and outputs the result.
* [`client_json`](client_json.rs) - A simple program that GETs some json, reads the body asynchronously, parses it with
serde and outputs the result.

### Servers

Expand All @@ -42,22 +45,36 @@ futures-util = { version = "0.3", default-features = false }

* [`gateway`](gateway.rs) - A server gateway (reverse proxy) that proxies to the `hello` service above.

* [`graceful_shutdown`](graceful_shutdown.rs) - A server that has a timeout for incoming connections and does graceful connection shutdown.
* [`graceful_shutdown`](graceful_shutdown.rs) - A server that has a timeout for incoming connections and does graceful
connection shutdown.

* [`http_proxy`](http_proxy.rs) - A simple HTTP(S) proxy that handle and upgrade `CONNECT` requests and then proxy data between client and remote server.
* [`http_proxy`](http_proxy.rs) - A simple HTTP(S) proxy that handle and upgrade `CONNECT` requests and then proxy data
between client and remote server.

* [`multi_server`](multi_server.rs) - A server that listens to two different ports, a different `Service` per port.

* [`params`](params.rs) - A webserver that accept a form, with a name and a number, checks the parameters are presents and validates the input.
* [`params`](params.rs) - A webserver that accept a form, with a name and a number, checks the parameters are presents
and validates the input.

* [`send_file`](send_file.rs) - A server that sends back content of files using tokio-util to read the files asynchronously.
* [`send_file`](send_file.rs) - A server that sends back content of files using tokio-util to read the files
asynchronously.

* [`service_struct_impl`](service_struct_impl.rs) - A struct that manually implements the `Service` trait and uses a shared counter across requests.
* [`service_struct_impl`](service_struct_impl.rs) - A struct that manually implements the `Service` trait and uses a
shared counter across requests.

* [`single_threaded`](single_threaded.rs) - A server only running on 1 thread, so it can make use of `!Send` app state (like an `Rc` counter).
* [`single_threaded`](single_threaded.rs) - A server only running on 1 thread, so it can make use of `!Send` app state (
like an `Rc` counter).

* [`state`](state.rs) - A webserver showing basic state sharing among requests. A counter is shared, incremented for every request, and every response is sent the last count.
* [`state`](state.rs) - A webserver showing basic state sharing among requests. A counter is shared, incremented for
every request, and every response is sent the last count.

* [`upgrades`](upgrades.rs) - A server and client demonstrating how to do HTTP upgrades (such as WebSockets).

* [`web_api`](web_api.rs) - A server consisting in a service that returns incoming POST request's content in the response in uppercase and a service that calls the first service and includes the first service response in its own response.
* [`web_api`](web_api.rs) - A server consisting in a service that returns incoming POST request's content in the
response in uppercase and a service that calls the first service and includes the first service response in its own
response.

* [`multi_layer_proxy`](multi_layer_proxy.rs) - In this configuration we have a `public` `master` server, which accepts
**outgoing** connections from `endpoint` servers.
The reason for using outgoing connections, is to avoid the need to open firewall ports.
The `master` will receive requests and forward them one of the servers connected to it.