flask

Crates.ioflask
lib.rsflask
version2.1.1
sourcesrc
created_at2020-03-22 19:30:34.812442
updated_at2023-06-17 20:34:12.148953
descriptioncreate http Request/Response objects from a raw TcpStream
homepage
repositoryhttps://github.com/bpmason1/flask-rs
max_upload_size
id221518
size36,176
Brian Mason (bpmason1)

documentation

README

Build Status [minimum rustc 1.31

flask

Flask is a tool for storing the contents of the TcpStream and creating an http Request/Response

using flask to reverse proxy incoming HTTP requests from a TCPStream to address SocketAddr

use flask::httpx::read_http_request;

fn proxy_tcp_stream(stream: TcpStream, proxy_addr: SocketAddr) {
    let _proxy_add_str = format!("{}", proxy_addr);
    let proxy_addr_hdr = HeaderValue::from_str(&_proxy_add_str).unwrap();

    let mut req = read_http_request(stream.try_clone().unwrap()).unwrap();
    
    // In a real system you should implement remove_hop_by_hop_headers.  It's commented out here for simplicity.
    // *req.headers_mut() = remove_hop_by_hop_headers(req.headers());

    let req_headers = req.headers_mut();
    req_headers.remove(http::header::HOST);
    req_headers.insert(http::header::HOST, proxy_addr_hdr);
    handle_request(stream, req);
}
Commit count: 73

cargo fmt