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: MethodHTTP method (GET, POST, etc)
path: StringNormalized 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
impl RequestContext
Sourcepub fn new(method: Method, path: impl Into<String>) -> Self
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}Sourcepub fn insert_header(
&mut self,
key: impl Into<String>,
value: impl Into<String>,
)
pub fn insert_header( &mut self, key: impl Into<String>, value: impl Into<String>, )
Insert a header (key will be lowercased).
Sourcepub fn insert_query(&mut self, key: impl Into<String>, value: impl Into<String>)
pub fn insert_query(&mut self, key: impl Into<String>, value: impl Into<String>)
Insert a query parameter.
Sourcepub fn set_client_ip(&mut self, ip: impl Into<String>)
pub fn set_client_ip(&mut self, ip: impl Into<String>)
Set client IP.
Trait Implementations§
Source§impl Clone for RequestContext
impl Clone for RequestContext
Source§fn clone(&self) -> RequestContext
fn clone(&self) -> RequestContext
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for RequestContext
impl RefUnwindSafe for RequestContext
impl Send for RequestContext
impl Sync for RequestContext
impl Unpin for RequestContext
impl UnwindSafe for RequestContext
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more