pub struct HttpRequestBuilder { /* private fields */ }Expand description
HTTP 请求构建器 (Fluent API)
使用流式 API 构建完整的 HTTP 请求,自动添加标准 headers。
§Examples
use url::Url;
use aria2_core::http::request_response::{HttpRequestBuilder, HttpMethod};
let url = Url::parse("http://example.com/api").unwrap();
let request = HttpRequestBuilder::new(HttpMethod::Get, url)
.header("Accept", "application/json")
.build()
.unwrap();Implementations§
Source§impl HttpRequestBuilder
impl HttpRequestBuilder
Sourcepub fn new(method: HttpMethod, url: Url) -> Self
pub fn new(method: HttpMethod, url: Url) -> Self
Sourcepub fn build(self) -> Result<HttpRequest>
pub fn build(self) -> Result<HttpRequest>
构建最终的 HTTP 请求
自动添加以下标准 headers:
- Host: 从 URL 中提取
- User-Agent: aria2-rust/1.0
- Accept: /
- Connection: close
- Content-Length: 如果有 body
§Returns
构建完成的 HttpRequest,或错误信息
Auto Trait Implementations§
impl Freeze for HttpRequestBuilder
impl RefUnwindSafe for HttpRequestBuilder
impl Send for HttpRequestBuilder
impl Sync for HttpRequestBuilder
impl Unpin for HttpRequestBuilder
impl UnsafeUnpin for HttpRequestBuilder
impl UnwindSafe for HttpRequestBuilder
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