pub struct HttpRequest {
pub line: HttpRequestLine,
pub headers: HeaderList,
pub body: Vec<u8>,
pub content_length: Option<u64>,
pub chunked: bool,
pub keep_alive: bool,
}Expand description
HTTP/1.1 请求
Fields§
§line: HttpRequestLine请求行
headers: HeaderList请求头(名称已规范化为小写)
body: Vec<u8>请求体(未解析原始字节)
content_length: Option<u64>长度已确认(Content-Length)
chunked: bool是否 chunked 编码
keep_alive: bool是否为 keep-alive
Implementations§
Source§impl HttpRequest
impl HttpRequest
Sourcepub fn new(method: Box<str>, target: Box<str>, version: Box<str>) -> Self
pub fn new(method: Box<str>, target: Box<str>, version: Box<str>) -> Self
创建新请求
keep_alive 默认值按 RFC 7230 §6.3 / RFC 1945 §1.3:
- HTTP/1.0 默认关闭连接(仅显式
Connection: keep-alive才保持) - HTTP/1.1 默认保持(仅显式
Connection: close才关闭)
Sourcepub fn get_header<'a>(&'a self, name: &str) -> Option<&'a str>
pub fn get_header<'a>(&'a self, name: &str) -> Option<&'a str>
查找头部值(按规范化小写名称)
Trait Implementations§
Source§impl Clone for HttpRequest
impl Clone for HttpRequest
Source§fn clone(&self) -> HttpRequest
fn clone(&self) -> HttpRequest
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · 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 HttpRequest
impl RefUnwindSafe for HttpRequest
impl Send for HttpRequest
impl Sync for HttpRequest
impl Unpin for HttpRequest
impl UnsafeUnpin for HttpRequest
impl UnwindSafe for HttpRequest
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