cargo run --release
# proxy_config.toml
[[routes]]
from = "stremio-addon-proxy.herokuapp.com/helloworld"
to = "https://stremio-addon-helloworld.herokuapp.com"
[[routes]]
from = "stremio-addon-proxy.herokuapp.com/rust-addon"
to = "https://stremio-addon-example.herokuapp.com"
- Deployed addons and the proxy on Heroku may be broken for testing purposes.
- The first response may be slow because of Heroku dyno cold start.
- The proxy may have non-standard configuration - e.g. disabled cache.
- Addons and the proxy is currently deployed manually by Heroku CLI.
cargo bench
See /benches/proxy_benchmark.rs
Run
cargo make verify
before the push.
-
If you don't have
cargo-make
, install it by the commandcargo install cargo-make
-
You can run also individual
verify
sub-commands:cargo make fmt
orcargo fmt
cargo make clippy
cargo make test
orcargo test
-
Tested with:
rustc 1.44.1 (c7087fe00 2020-06-17)
rustc 1.46.0-nightly (feb3536eb 2020-06-09)
- Proxy is created and then started in
main.rs
. - New proxy requires callback
on_request
and HTTP client that will be sent toon_request
. - The most important code is in
proxy.rs
-Proxy::start
:- The proxy tries to load
ProxyConfig
and open database. - The proxy creates channel(s) for communication between the core and
on_request
callbacks (it's useful e.g. forProxyConfig
reloading though API calls). - The server is started.
- The proxy tries to load
- The most important function in this layer is
on_request
(inon_request.rs
). on_request
receives user's request from the proxy core and then:- The request is passed into middleware pipeline (function
apply_request_middlewares
). - Middlewares return modified request or custom / error / cached response. Middlewares may invoke side-effects like the cache reloading during their execution.
- If the pipeline result is a response, then the response is returned by the proxy server.
- If the pipeline result is a request, then the request is sent and a successful valid response is cached and returned by the proxy server.
- The request is passed into middleware pipeline (function
- Only business/domain specific rules are set in
validations.rs
validate_request
andvalidate_reponse
.