Skip to main content

RequestContext

Struct RequestContext 

Source
pub struct RequestContext {
    pub method: Method,
    pub path: String,
    pub query: HashMap<String, String>,
    pub headers: HashMap<String, String>,
    pub body: Option<Vec<u8>>,
    pub client_ip: Option<String>,
}
Expand description

Represents a normalized HTTP request inside Bulwark.

This is NOT a raw HTTP request. Everything here is meant to be:

  • explicit
  • predictable
  • safe to inspect

Fields§

§method: Method

HTTP method (GET, POST, etc)

§path: String

Normalized path (no query string)

§query: HashMap<String, String>

Query parameters (?a=b&c=d)

§headers: HashMap<String, String>

Request headers (lowercased keys)

§body: Option<Vec<u8>>

Raw request body (optional)

§client_ip: Option<String>

Client IP (if known)

Implementations§

Source§

impl RequestContext

Source

pub fn new(method: Method, path: impl Into<String>) -> Self

Create a new empty request context.

Examples found in repository?
examples/basic_api.rs (line 5)
3fn main() {
4    // Simulasi request masuk
5    let ctx = RequestContext::new(Method::POST, "/login");
6
7    log_request(&ctx);
8
9    if is_login(&ctx) {
10        println!("Login request detected");
11    } else {
12        println!("Not a login request");
13    }
14}
Source

pub fn insert_header( &mut self, key: impl Into<String>, value: impl Into<String>, )

Insert a header (key will be lowercased).

Source

pub fn insert_query(&mut self, key: impl Into<String>, value: impl Into<String>)

Insert a query parameter.

Source

pub fn set_body(&mut self, body: Vec<u8>)

Set request body.

Source

pub fn set_client_ip(&mut self, ip: impl Into<String>)

Set client IP.

Source

pub fn header(&self, key: &str) -> Option<&String>

Get a header value (case-insensitive).

Source

pub fn has_body(&self) -> bool

Check if request has a body.

Trait Implementations§

Source§

impl Clone for RequestContext

Source§

fn clone(&self) -> RequestContext

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for RequestContext

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.