Skip to content

Commit

Permalink
chore: add todo list
Browse files Browse the repository at this point in the history
  • Loading branch information
nixpig committed Jan 7, 2024
1 parent 98ce76e commit 7df9e6e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
18 changes: 18 additions & 0 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
To implement:

- [ ] Get config from CLI args
- [ ] Get config from YAML config file
- [ ] Merge configs and pass into 'startup' function
- [ ] Proxy requests for all HTTP methods to 'target'
- [ ] Strip hop-by-hop headers
- [ ] Add `x-forwarded-for` header
- [ ] Implement TLS/SSL support
- [ ] Implement upgrade for web sockets

---

Things to consider:

- [ ] Request body and content types, e.g. application/json, x-www-form-urlencoded, multipart/form-data
- [ ] Query parameters
- [ ] More 'complex' scenarios than just a JSON REST API request.
4 changes: 4 additions & 0 deletions src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ pub async fn parse_incoming_request(
String::from(header_value.trim()),
);
}

request
.headers
.insert(String::from("host"), String::from("localhost:3000"));
}

if let Some(content_length) = request.headers.get("content-length") {
Expand Down
10 changes: 7 additions & 3 deletions src/startup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,10 @@ async fn handle_connection(

let port = proxy_request.port;
let request_str = build_proxy_request(proxy_request)?;
println!("request_str: {}", request_str);

let address = format!("{}:{}", addr.ip(), port);
println!("address: {}", address);

if let Ok(mut remote_stream) = TcpStream::connect(address).await {
let log = format!(
Expand All @@ -64,14 +66,16 @@ async fn handle_connection(

remote_stream.write_all(request_str.as_bytes()).await?;

let mut response = String::new();
let mut response = vec![];

remote_stream
.read_to_string(&mut response)
.read_buf(&mut response)
.await
.expect("Unable to read from remote stream");

stream.write_all(response.as_bytes()).await?;
let response_bytes: &[u8] = &response;

stream.write_all(response_bytes).await?;
} else {
eprintln!("Unable to connect to remote server");
}
Expand Down

0 comments on commit 7df9e6e

Please sign in to comment.