@@ -14,7 +14,8 @@ A HTTP proxy server library intended to be a backend of application like Burp pr
1414use std::path::PathBuf;
1515
1616use clap::{Args, Parser};
17- use http_mitm_proxy::{DefaultClient, MitmProxy};
17+ use futures::StreamExt;
18+ use http_mitm_proxy::{default_client::Upgrade, DefaultClient, MitmProxy};
1819use moka::sync::Cache;
1920use tracing_subscriber::EnvFilter;
2021
@@ -100,11 +101,36 @@ async fn main() {
100101 let uri = req.uri().clone();
101102
102103 // You can modify request here
103- // or You can just return response anyware
104+ // or You can just return response anywhere
104105
105- let (res, _upgrade ) = client.send_request(req).await?;
106+ let (res, upgrade ) = client.send_request(req).await?;
106107
107108 println!("{} -> {}", uri, res.status());
109+ if let Some(upgrade) = upgrade {
110+ // If the response is an upgrade, e.g. Websocket, you can see traffic.
111+ // Modifying upgraded traffic is not supported yet.
112+
113+ // You can try https://echo.websocket.org/.ws to test websocket.
114+ // But you need to disable alpn of DefaultClient to disable HTTP2 because echo.websocket.org does not support HTTP/2 for Websocket.
115+ // It should be match incoming and outgoing HTTP version on DefaultClient, I'll fix this later. #54
116+ println!("Upgrade connection");
117+ let Upgrade {
118+ mut client_to_server,
119+ mut server_to_client,
120+ } = upgrade;
121+ let url = uri.to_string();
122+ tokio::spawn(async move {
123+ while let Some(data) = client_to_server.next().await {
124+ println!("Client -> Server: {} {:?}", url, data);
125+ }
126+ });
127+ let url = uri.to_string();
128+ tokio::spawn(async move {
129+ while let Some(data) = server_to_client.next().await {
130+ println!("Server -> Client: {} {:?}", url, data);
131+ }
132+ });
133+ }
108134
109135 // You can modify response here
110136
0 commit comments