4 releases

0.1.3 Jun 17, 2020
0.1.2 Jun 17, 2020
0.1.1 Jun 17, 2020
0.1.0 Jun 17, 2020

#322 in WebSocket

MIT license

13KB
280 lines

Designed for HAWK

Example

use tokio::net::TcpListener;

use http_rs::Http;
use websocket_rs::{ Websocket, Opcode };

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let mut listener = TcpListener::bind("127.0.0.1:8080").await?;

    println!("Listening for websocket connections on 127.0.0.1:8080");

    while let Ok((stream, addr)) = listener.accept().await {
        tokio::spawn(async move {
            println!("New connection from {:?}", addr);

            let mut http = Http::new(stream);

            if let Some(req) = http.next().await {
                println!("{:?}", req);
            }
        });
    }

    Ok(())
}

TODO

  • Handle errors properly
  • Support GET/POST request
  • Parse Request-Line & headers
  • Read POST body
  • Generate a suitable response
  • Handles Compression
  • Serve static files from disk

Dependencies

~8–14MB
~165K SLoC