Actix-web : implement HTTPS proxy

HTTPS proxy works in a different way than HTTP proxy.

First client sends CONNECT

CONNECT www.google.com:443 HTTP/1.1
Host: www.google.com:443
Proxy-Connection: keep-alive
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36

image029

After proxy server establishes a TCP connection to target and response 200 to client, a tunnel is opened and this TCP connection is proxied with raw data.

My question is: How can I access the raw socket after sending HTTP response 200 to client?

HttpServer::new(|| {
        App::new()
            .wrap(middleware::Compress::default())
            .wrap(middleware::Logger::default())
            .default_service(web::route().to_async(handle_connect))
    }
)
.bind_rustls(format!("0.0.0.0:{}", port), config)
.expect(&format!("Unable to bind on rustls port {}", port))
.workers(1)
.start();


fn handle_connect(req: HttpRequest, stream: web::Payload) -> impl futures01::future::Future<Item=HttpResponse, Error=()> {
    
    async_handle_connect_request(req, stream).unit_error().boxed_local().compat()
}



async fn async_handle_connect_request(_req: HttpRequest, _stream: web::Payload) -> HttpResponse {
    return HttpResponse::Ok().finish();
}

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.