Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dependency updates #167

Merged
merged 2 commits into from
Mar 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
727 changes: 291 additions & 436 deletions Cargo.lock

Large diffs are not rendered by default.

12 changes: 7 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ edition = "2021"
default-run = "camo"

[dependencies]
axum = "0.6"
axum = "0.7"
clap = { version = "4", features = ["cargo", "derive", "env", "wrap_help"] }
hex = "0.4"
hmac = "0.12"
hyper = { version = "0.14", features = ["full"] }
hyper-rustls = { version = "0.24", features = ["http2"] }
http-body-util = "0.1"
hyper = { version = "1", features = ["full"] }
hyper-rustls = { version = "0.26", features = ["http2"] }
hyper-util = "0.1"
sha-1 = "0.10"
thiserror = "1.0"
tokio = { version = "1", features = ["full"] }
Expand All @@ -23,5 +25,5 @@ tracing-subscriber = { version = "0.3", features = ["json"] }
url = "2"

[dev-dependencies]
reqwest = "0.11"
wiremock = "0.5"
reqwest = "0.12"
wiremock = "0.6"
6 changes: 4 additions & 2 deletions src/bin/camo.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::{net::SocketAddr, str::FromStr};

use clap::Parser;
use tokio::net::TcpListener;

use camo_rs::{server, settings::LogFormat, Settings};

Expand Down Expand Up @@ -36,9 +37,10 @@ async fn main() {
}

let listen_addr = SocketAddr::from_str(&settings.listen).unwrap();
let listener = TcpListener::bind(&listen_addr).await.unwrap();

let server = server::build(settings);
axum::Server::bind(&listen_addr)
.serve(server.into_make_service())
axum::serve(listener, server.into_make_service())
.with_graceful_shutdown(shutdown_signal())
.await
.unwrap()
Expand Down
9 changes: 6 additions & 3 deletions src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

use std::string::FromUtf8Error;

use axum::response::{IntoResponse, Response};
use axum::{
body::Body,
response::{IntoResponse, Response},
};
use hex::FromHexError;
use hyper::{header, Body, StatusCode};
use hyper::{header, StatusCode};
use thiserror::Error;
use tracing::{info, warn};

Expand Down Expand Up @@ -131,7 +134,7 @@ pub enum ProxyError {

/// Returned if the request to the upstream failed.
#[error("upstream error: {0}")]
UpstreamError(#[source] hyper::Error),
UpstreamError(#[source] hyper_util::client::legacy::Error),

/// Returned if the connection didn't get established until the configurable
/// timeout expired.
Expand Down
20 changes: 13 additions & 7 deletions src/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@

use std::time::Duration;

use axum::http::HeaderValue;
use hyper::{header, Body, HeaderMap, Method, Request, Response};
use axum::{http::HeaderValue, response::IntoResponse};
use http_body_util::Empty;
use hyper::{body::Bytes, header, HeaderMap, Method, Request, Response};
use hyper_util::{
client::legacy::{connect::HttpConnector, Client},
rt::TokioExecutor,
};

use crate::{errors::ProxyError, header_wrangler};

Expand All @@ -12,7 +17,7 @@ use crate::{errors::ProxyError, header_wrangler};
pub struct Proxy {
via_header: String,
upstream_timeout: usize,
http_client: hyper::Client<hyper_rustls::HttpsConnector<hyper::client::HttpConnector>>,
http_client: Client<hyper_rustls::HttpsConnector<HttpConnector>, Empty<Bytes>>,
}

impl Proxy {
Expand All @@ -24,11 +29,12 @@ impl Proxy {
pub fn new(via_header: &str, upstream_timeout: usize) -> Self {
let https = hyper_rustls::HttpsConnectorBuilder::new()
.with_native_roots()
.expect("native roots to be there")
.https_or_http()
.enable_http1()
.enable_http2()
.build();
let http_client = hyper::Client::builder().build::<_, Body>(https);
let http_client = Client::builder(TokioExecutor::new()).build::<_, Empty<Bytes>>(https);

Self {
via_header: via_header.to_owned(),
Expand All @@ -47,13 +53,13 @@ impl Proxy {
method: &Method,
headers: &HeaderMap,
target: &str,
) -> Result<Response<Body>, ProxyError> {
) -> Result<Response<axum::body::Body>, ProxyError> {
let mut req = Request::builder()
.method(method)
.uri(target)
.header(header::USER_AGENT, &self.via_header)
.header(header::VIA, &self.via_header)
.body(Body::empty())
.body(Empty::new())
.map_err(ProxyError::RequestBuildingFailed)?;

header_wrangler::assign_filtered_request_headers(headers, req.headers_mut());
Expand All @@ -73,6 +79,6 @@ impl Proxy {
HeaderValue::from_str(target).expect("target is always a valid URL at this point"),
);

Ok(res)
Ok(res.into_response())
}
}
3 changes: 2 additions & 1 deletion src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use std::str::FromStr;

use axum::{
body::Body,
extract::{Path, State},
http::HeaderValue,
response::{IntoResponse, Response},
Expand All @@ -11,7 +12,7 @@ use axum::{
};
use hyper::{
header::{self, HeaderName},
Body, HeaderMap, Method,
HeaderMap, Method,
};
use tracing::{instrument, Span};

Expand Down
5 changes: 2 additions & 3 deletions tests/proxy.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use axum::body::Body;
use hyper::{HeaderMap, Method};
use wiremock::MockServer;

Expand All @@ -6,9 +7,7 @@ use camo_rs::{errors::ProxyError, proxy::*};
pub mod helpers;
use helpers::wiremock::*;

async fn run_proxy_request(
upstream: &MockServer,
) -> Result<hyper::Response<hyper::Body>, ProxyError> {
async fn run_proxy_request(upstream: &MockServer) -> Result<hyper::Response<Body>, ProxyError> {
let proxy = Proxy::new("camo-rs", 10);
let headers = HeaderMap::new();

Expand Down
11 changes: 6 additions & 5 deletions tests/server.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::net::{SocketAddr, TcpListener};
use std::net::SocketAddr;

use tokio::net::TcpListener;
use wiremock::MockServer;

use camo_rs::{server::*, AuthenticatedTarget, Settings};
Expand All @@ -8,7 +9,9 @@ pub mod helpers;
use helpers::{application::*, wiremock::*};

async fn run_test_server(mut settings: Settings) -> (SocketAddr, reqwest::Client) {
let listener = TcpListener::bind("127.0.0.1:0").expect("could not bind ephemeral socket");
let listener = TcpListener::bind("127.0.0.1:0")
.await
.expect("could not bind ephemeral socket");
let listen_addr = listener.local_addr().unwrap();
let client = reqwest::Client::builder()
.redirect(reqwest::redirect::Policy::none())
Expand All @@ -18,9 +21,7 @@ async fn run_test_server(mut settings: Settings) -> (SocketAddr, reqwest::Client
settings.root_url = format!("http://{listen_addr}/");

tokio::spawn(async move {
axum::Server::from_tcp(listener)
.unwrap()
.serve(build(settings).into_make_service())
axum::serve(listener, build(settings).into_make_service())
.await
.unwrap()
});
Expand Down