[−][src]Trait roa::forward::Forward
A context extension Forward
used to parse X-Forwarded-*
request headers.
Required methods
fn host(&self) -> Result<String>
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: Context<()>) -> Result { println!("host: {}", ctx.host()?); Ok(()) }
fn client_ip(&self) -> IpAddr
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: Context<()>) -> Result { println!("client ip: {}", ctx.client_ip()); Ok(()) }
fn forwarded_ips(&self) -> Vec<IpAddr>
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: Context<()>) -> Result { println!("forwarded ips: {:?}", ctx.forwarded_ips()); Ok(()) }
fn forwarded_proto(&self) -> Option<Result<String>>
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: Context<()>) -> Result { if let Some(result) = ctx.forwarded_proto() { println!("forwarded proto: {}", result?); } Ok(()) }