-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from w-henderson/proxy
Implement HTTP proxy
- Loading branch information
Showing
16 changed files
with
297 additions
and
177 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
pub mod cache; | ||
pub mod load_balancer; | ||
pub mod logger; | ||
pub mod pipe; | ||
pub mod proxy; | ||
pub mod rand; | ||
pub mod route; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
use std::io::{Read, Write}; | ||
use std::net::{Shutdown, TcpStream}; | ||
|
||
/// Pipe bytes from one stream to another, up to 1KiB at a time. | ||
pub fn pipe(source: &mut TcpStream, destination: &mut TcpStream) -> Result<(), ()> { | ||
let mut buf: [u8; 1024] = [0; 1024]; | ||
|
||
loop { | ||
let length = source.read(&mut buf).map_err(|_| ())?; | ||
|
||
if length == 0 { | ||
destination.shutdown(Shutdown::Both).map_err(|_| ())?; | ||
break; | ||
} | ||
|
||
if let Ok(_) = destination.write(&buf[..length]) { | ||
destination.flush().map_err(|_| ())?; | ||
} | ||
} | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.