使用旧的Rust 2015
| 0.2.0 |  | 
|---|---|
| 0.1.5 |  | 
#106 在 #http-response
用于 boguin
310KB
 4.5K  SLoC
带有URL的HTTP
当使用HTTP时,你是否曾烦恼过无法在Rust中使用常规URL?
此crate修改了HTTP crate以使用URL进行请求。
请参阅我的博客文章和boguin HTTP客户端。
原始README
一个通用库,包含常用的HTTP类型
有关此crate的更多信息,请参阅crate文档。
用法
要使用 http,请先将以下内容添加到您的 Cargo.toml
[dependencies]
http = "0.1"
然后,将以下内容添加到您的crate中
extern crate http;
use http::{Request, Response};
fn main() {
    // ...
}
示例
创建一个HTTP请求
extern crate http;
use http::Request;
fn main() {
    let request = Request::builder()
      .uri("https://rust-lang.net.cn/")
      .header("User-Agent", "awesome/1.0")
      .body(())
      .unwrap();
}
创建一个HTTP响应
extern crate http;
use http::{Response, StatusCode};
fn main() {
    let response = Response::builder()
      .status(StatusCode::MOVED_PERMANENTLY)
      .header("Location", "https://rust-lang.net.cn/install.html")
      .body(())
      .unwrap();
}
许可
许可协议为以下之一
- Apache License,版本2.0 (LICENSE-APACHE 或 https://apache.ac.cn/licenses/LICENSE-2.0)
- MIT许可 (LICENSE-MIT 或 https://open-source.org.cn/licenses/MIT)
贡献
除非您明确声明,否则根据Apache-2.0许可证定义的您有意提交以包含在作品中的任何贡献,均将根据上述方式双许可,无任何附加条款或条件。
依赖关系
~1.5MB
~55K SLoC