#http-client #client-server #http-server #tls #limited #io #transport

no-std http_io

一个包含HTTP客户端和服务器,依赖关系较少的库

20个版本

0.2.18 2022年12月4日
0.2.17 2022年9月10日
0.2.15 2022年8月19日
0.2.10 2021年7月29日
0.1.0 2019年3月13日

#9 in #limited

Download history 9/week @ 2024-04-22 2/week @ 2024-05-06 1/week @ 2024-05-13 5/week @ 2024-05-20 2/week @ 2024-05-27 5/week @ 2024-06-03 5/week @ 2024-06-10 7/week @ 2024-06-24 93/week @ 2024-07-01 9/week @ 2024-07-15 186/week @ 2024-07-29

每月195次下载
4个crate(2个直接)中使用

MIT/Apache

125KB
3.5K SLoC

http_io 最新版本

包含HTTP客户端和服务器的crate。

  • 设计为具有有限的依赖关系,支持#![no_std]
  • 专注于流式IO。
  • 支持提供自己的传输。
  • 支持HTTPS

no_std构建需要nightly,因为它依赖于alloc crate。

示例

use http_io::error::Result;
use std::fs::File;
use std::io;

fn main() -> Result<()> {
    // Stream contents of url to stdout
    let mut body = http_io::client::get("https://postman-echo.com/get")?;
    io::copy(&mut body, &mut std::io::stdout())?;

    // Stream contents of file to remote server
    let file = File::open("src/client.rs")?;
    http_io::client::put("https://postman-echo.com/put", file)?;
    Ok(())
}

选择TLS后端

默认情况下,http_io使用native-tls作为其TLS库(HTTPS支持)。它还支持其他两个TLS库,rustlsopenssl。这些其他“后端”可以通过功能选择

$ # If you want to use `rustls`:
$ cargo build --no-default-features --features std,ssl-rustls
$ # If you want to use `openssl`:
$ cargo build --no-default-features --features std,ssl-openssl

依赖

~0.8–12MB
~152K SLoC