-
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
23 changed files
with
1,100 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
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,3 @@ | ||
## 0.1.0 - 17-12-2024 | ||
|
||
* Initial release |
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,19 @@ | ||
Copyright (c) 2024 redirection.io | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
this software and associated documentation files (the "Software"), to deal in | ||
the Software without restriction, including without limitation the rights to | ||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
the Software, and to permit persons to whom the Software is furnished to do so, | ||
subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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 @@ | ||
# Actix proxy service | ||
|
||
Reverse HTTP and websocket service for Actix Web. | ||
|
||
Provides a service for Actix Web that can be used to proxy requests from client to another server. | ||
|
||
## Examples | ||
|
||
```rust | ||
use actix_web::{guard, middleware, App, HttpServer}; | ||
use redirectionio_actix_proxy::{HttpPeer, Proxy}; | ||
use std::net::ToSocketAddrs; | ||
|
||
#[actix_rt::main] | ||
async fn main() -> std::io::Result<()> { | ||
let address = "127.0.0.1:80" | ||
.to_socket_addrs() | ||
.expect("error getting addresses") | ||
.next() | ||
.expect("cannot get address"); | ||
|
||
HttpServer::new(move || { | ||
App::new() | ||
.service(Proxy::new(HttpPeer::new(address, "my-proxy.com"))) | ||
}) | ||
.bind(("127.0.0.1", 8080))? | ||
.workers(2) | ||
.run() | ||
.await | ||
} | ||
``` | ||
|
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.