Upstream Module for Pingora
This crate helps configure Pingora’s upstream functionality. It is most useful in combination
with the virtual-hosts-module crate that allows applying multiple upstream configurations
conditionally.
Currently only one configuration option is provided: upstream (--upstream as command line
option). The value should be a URL like http://127.0.0.1:8081 or https://example.com.
Supported URL schemes are http:// and https://. Other than the scheme, only host name and
port are considered. Other parts of the URL are ignored if present.
The UpstreamHandler type has to be called in both request_filter and upstream_peer
Pingora Proxy phases. The former selects an upstream peer and modifies the request by adding
the appropriate Host header. The latter retrieves the previously selected upstream peer.
use async_trait;
use UpstreamHandler;
use RequestFilter;
use Error;
use HttpPeer;
use ;
To create a handler, you will typically read its configuration from a configuration file, optionally combined with command line options. The following code will extend Pingora's usual configuration file and command line options accordingly.
use ;
use ;
use Server;
use ;
use StructOpt;
let opt = from_args;
let mut conf = opt
.server
.conf
.as_ref
.and_then
.unwrap_or_else;
conf.upstream.merge_with_opt;
let mut server = new_with_opt_and_conf;
server.bootstrap;
let upstream_handler: UpstreamHandler = conf.upstream.try_into.unwrap;
For complete and more realistic code see virtual-hosts example in the repository.