Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tickbh/wenmeng
http1.1/http2 server/client by rust
https://github.com/tickbh/wenmeng
client http http-client http-requests http-server http2 httpclient https server
Last synced: about 1 month ago
JSON representation
http1.1/http2 server/client by rust
- Host: GitHub
- URL: https://github.com/tickbh/wenmeng
- Owner: tickbh
- License: apache-2.0
- Created: 2023-08-31T01:54:31.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-02-27T06:47:49.000Z (11 months ago)
- Last Synced: 2024-11-21T09:38:08.155Z (about 2 months ago)
- Topics: client, http, http-client, http-requests, http-server, http2, httpclient, https, server
- Language: Rust
- Homepage:
- Size: 517 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# wenmeng
一个包含http1.1及http2的服务器及客户端的实现, 依赖tokio实现
## 使用方法
简单的hello world示例
```rust
use std::{env, error::Error};
use tokio::net::TcpListener;
use webparse::{Request, Response};
use wenmeng::{self, ProtResult, RecvStream, Server, RecvRequest};#[tokio::main]
async fn main() -> Result<(), Box> {
let addr = env::args()
.nth(1)
.unwrap_or_else(|| "127.0.0.1:8080".to_string());
let server = TcpListener::bind(&addr).await?;
println!("Listening on: {}", addr);
loop {
let (stream, _) = server.accept().await?;
tokio::spawn(async move {
let mut server = Server::new(stream);
async fn operate(req: RecvRequest) -> ProtResult>> {
let response = Response::builder()
.version(req.version().clone())
.body("Hello World".to_string())?;
Ok(Some(response))
}
let _ = server.incoming(operate).await;
});
}
}
```## 客户端使用方法
> http1/http2通用, recv可以接收多个返回及服务端的推送信息
```rust
use webparse::Request;
use wenmeng::{Client, ProtResult};async fn test_http2() -> ProtResult<()> {
let url = "http://nghttp2.org/"; //"http://127.0.0.1:8080/"
let req = Request::builder().method("GET").url(url).body("").unwrap();let client = Client::builder().connect(url).await.unwrap();
let (mut recv, sender) = client.send2(req.into_type()).await?;
let mut res = recv.recv().await.unwrap();
res.body_mut().wait_all().await;
println!("res = {}", res);let req = Request::builder()
.method("GET")
.url(url.to_owned() + "blog/")
.body("")
.unwrap();
sender.send(req.into_type()).await?;
let res = recv.recv().await.unwrap();
println!("res = {}", res);
Ok(())
}
```## License
Apache License, Version 2.0 ([LICENSE-APACHE](./LICENSE) or [https://apache.org/licenses/LICENSE-2.0](https://apache.org/licenses/LICENSE-2.0))