-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
890 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ members = [ | |
"io", | ||
"postgres", | ||
"postgres-codegen", | ||
"reverse-proxy", | ||
"router", | ||
"server", | ||
"service", | ||
|
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
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
[package] | ||
name = "redirectionio-xitca-proxy" | ||
version = "0.1.0" | ||
authors = ["Joel Wurtz <[email protected]>"] | ||
edition = "2021" | ||
description = "Xitca web reverse HTTP and Websocket proxy" | ||
|
||
[dependencies] | ||
bytes = "1.9.0" | ||
lazy_static = "1.5.0" | ||
xitca-client = { version = "0.1.0", features = ["dangerous", "openssl"] } | ||
xitca-http = "0.7.0" | ||
xitca-web = "0.7.0" | ||
|
||
[dev-dependencies] | ||
tokio = { version = "1.42.0", features = ["full"] } | ||
|
||
[[example]] | ||
name = "http_proxy" |
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 redirectionio_xitca_proxy::{HttpPeer, Proxy}; | ||
use std::net::ToSocketAddrs; | ||
use xitca_web::App; | ||
|
||
#[tokio::main] | ||
async fn main() -> std::io::Result<()> { | ||
let address = "github.com:443" | ||
.to_socket_addrs() | ||
.expect("error getting addresses") | ||
.next() | ||
.expect("cannot get address"); | ||
|
||
App::new() | ||
.at("", Proxy::new(HttpPeer::new(address, "github.com:443").tls(true))) | ||
.serve() | ||
.bind("127.0.0.1:8080")? | ||
.run() | ||
.await?; | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
use crate::forwarder::ForwardError; | ||
use std::error::Error; | ||
use std::fmt; | ||
use xitca_web::error::Error as XitcaError; | ||
|
||
#[derive(Debug)] | ||
pub enum ProxyError { | ||
CannotReadRequestBody(XitcaError), | ||
ForwardError(ForwardError), | ||
NoPeer, | ||
} | ||
|
||
impl fmt::Display for ProxyError { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
match self { | ||
Self::CannotReadRequestBody(e) => write!(f, "error when reading request body: {}", e), | ||
Self::ForwardError(e) => write!(f, "error when forwarding request: {}", e), | ||
Self::NoPeer => f.write_str("no peer found"), | ||
} | ||
} | ||
} | ||
|
||
impl Error for ProxyError { | ||
fn source(&self) -> Option<&(dyn Error + 'static)> { | ||
match self { | ||
Self::CannotReadRequestBody(err) => Some(err), | ||
Self::ForwardError(err) => Some(err), | ||
Self::NoPeer => None, | ||
} | ||
} | ||
} |
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,32 @@ | ||
use std::{error::Error, fmt}; | ||
|
||
/// Errors that can result from using a connector service. | ||
#[derive(Debug)] | ||
pub enum ForwardError { | ||
/// Failed to build a request from origin | ||
UriError(xitca_web::http::Error), | ||
} | ||
|
||
impl fmt::Display for ForwardError { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
match self { | ||
Self::UriError(_) => f.write_str("could not build request from origin"), | ||
} | ||
} | ||
} | ||
|
||
impl Error for ForwardError { | ||
fn source(&self) -> Option<&(dyn Error + 'static)> { | ||
match self { | ||
Self::UriError(err) => Some(err), | ||
} | ||
} | ||
} | ||
|
||
impl ForwardError { | ||
pub fn into_error_status(self) -> xitca_web::error::ErrorStatus { | ||
match self { | ||
Self::UriError(_) => xitca_web::error::ErrorStatus::bad_request(), | ||
} | ||
} | ||
} |
Oops, something went wrong.