cogo-http

Crates.iocogo-http
lib.rscogo-http
version0.1.13
sourcesrc
created_at2022-02-05 12:29:57.95672
updated_at2022-02-14 09:13:03.787795
descriptionA modern HTTP library.
homepagehttps://github.com/co-rs
repositoryhttps://github.com/co-rs/cogo-http.git
max_upload_size
id527399
size641,696
zxj (zhuxiujia)

documentation

README

cogo-http

  • Coroutine HTTP framework for Cogo, Original code fork from Hyper,We improved the underlying logic
  • support http server
  • support http client

Performance

per

example-server

#[deny(unused_variables)]
extern crate cogo_http;

use cogo_http::route::Route;
use cogo_http::server::{Request, Response};

fn hello(req: Request, res: Response) {
    res.send(b"Hello World!").unwrap();
}

fn main() {
    let _listening = cogo_http::Server::http("0.0.0.0:3000").unwrap()
        .handle(hello);
    println!("Listening on http://127.0.0.1:3000");
}

example-client

extern crate cogo_http;

use std::io;
use cogo_http::Client;
use cogo_http::header::Connection;

fn main() {
    let mut url = "http://www.baidu.com".to_string();

    let client = Client::new();

    let mut res = client.get(&url)
        .header(Connection::close())
        .send().unwrap();

    println!("Response: {}", res.status);
    println!("Headers:\n{}", res.headers);
    io::copy(&mut res, &mut io::stdout()).unwrap();
}
Commit count: 230

cargo fmt