Trait roa::forward::Forward [−][src]
A context extension Forward
used to parse X-Forwarded-*
request headers.
Required methods
fn host(&self) -> Option<&str>
[src]
Get true host.
- If “x-forwarded-host” is set and valid, use it.
- Else if “host” is set and valid, use it.
- Else throw Err(400 BAD REQUEST).
Example
use roa::{Context, Result}; use roa::forward::Forward; async fn get(ctx: &mut Context) -> Result { if let Some(host) = ctx.host() { println!("host: {}", host); } Ok(()) }
fn client_ip(&self) -> IpAddr
[src]
Get true client ip.
- If “x-forwarded-for” is set and valid, use the first ip.
- Else use the ip of
Context::remote_addr()
.
Example
use roa::{Context, Result}; use roa::forward::Forward; async fn get(ctx: &mut Context) -> Result { println!("client ip: {}", ctx.client_ip()); Ok(()) }
fn forwarded_ips(&self) -> Vec<IpAddr>
[src]
Get true forwarded ips.
- If “x-forwarded-for” is set and valid, use it.
- Else return an empty vector.
Example
use roa::{Context, Result}; use roa::forward::Forward; async fn get(ctx: &mut Context) -> Result { println!("forwarded ips: {:?}", ctx.forwarded_ips()); Ok(()) }
fn forwarded_proto(&self) -> Option<&str>
[src]
Try to get forwarded proto.
- If “x-forwarded-proto” is not set, return None.
- If “x-forwarded-proto” is set but fails to string, return Some(Err(400 BAD REQUEST)).
Example
use roa::{Context, Result}; use roa::forward::Forward; async fn get(ctx: &mut Context) -> Result { if let Some(proto) = ctx.forwarded_proto() { println!("forwarded proto: {}", proto); } Ok(()) }