simple_http_parser

Crates.iosimple_http_parser
lib.rssimple_http_parser
version0.3.5
sourcesrc
created_at2022-12-17 16:21:36.518688
updated_at2023-07-06 23:33:26.584033
descriptionConverts raw http request to a Request and build Response
homepage
repositoryhttps://github.com/matteac/http_parser
max_upload_size
id739939
size14,223
Mateo Acuña (matteac)

documentation

README

http_parser

Converts raw request to Request

Parse the raw http request to Request

    let listener = TcpListener::bind("0.0.0.0:7878").unwrap();
    for stream in listener.incoming() {
        let mut tcp_stream = stream.unwrap();
        let mut buffer = [0; 16384];
        tcp_stream.read(&mut buffer).unwrap();

        let raw_request = String::from_utf8_lossy(&buffer);

        match Request::from(&raw_request) {
            Ok(_) => {
                tcp_stream
                    .write_all(
                        b"HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n<h1>Hello World</h1>",
                    )
                    .unwrap();
            }
            Err(e) => {
                println!("{:?}", e);
            }
        }
    }
Commit count: 8

cargo fmt