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

Support http over unix domain sockets #392

Open
wants to merge 26 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
8ba7774
reduce lifetime of printer closure passed to client middleware
ducaale Dec 29, 2024
aa8fbf5
support http over unix domain sockets
ducaale Dec 29, 2024
fe56317
implement test server for http_unix
ducaale Dec 29, 2024
531dba9
add initial tests for http_unix
ducaale Dec 29, 2024
bf4b1b8
fix clippy warnings
ducaale Dec 29, 2024
80242c2
disable http_unix tests in windows
ducaale Dec 29, 2024
8cee2fe
add middleware for managing cookies
ducaale Dec 30, 2024
652e3df
add test for cookies
ducaale Dec 30, 2024
b6d59d9
avoid mocking host header
ducaale Dec 30, 2024
cb8d396
use shortened version of cfg unix check
ducaale Dec 30, 2024
c7fb645
throw an error if unix-socket used in unsupported os
ducaale Dec 30, 2024
e0791b3
provide complete example for unix-socket usage
ducaale Dec 30, 2024
f09a191
fix missing import
ducaale Dec 30, 2024
67730e1
check that host header is passed
ducaale Dec 30, 2024
de52108
Merge branch 'master' into http-over-unix-socket
ducaale Dec 30, 2024
0a80407
store unix_client in ClientWithMiddleware
ducaale Dec 31, 2024
3d887f0
Merge branch 'master' into http-over-unix-socket
ducaale Jan 2, 2025
2eb6367
Merge branch 'master' into http-over-unix-socket
ducaale Jan 7, 2025
31c4420
warn or error if unix-socket used with unsupported option
ducaale Jan 7, 2025
8bcbb0d
disable failing badssl.com tests
ducaale Jan 7, 2025
d601946
implement read timeout for unix_socket requests
ducaale Jan 7, 2025
c84e8ef
implement connect timeout for unix_socket requests
ducaale Jan 8, 2025
e362e7f
switch from read timeout to total timeout
ducaale Jan 11, 2025
92df488
revert disabling badssl tests
ducaale Jan 11, 2025
bd8dbdd
Merge branch 'master' into http-over-unix-socket
ducaale Jan 11, 2025
7db9b38
Merge branch 'master' into http-over-unix-socket
ducaale Jan 19, 2025
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
Prev Previous commit
Next Next commit
avoid mocking host header
ducaale committed Dec 30, 2024

Verified

This commit was signed with the committer’s verified signature.
0xNe0x1 0xNe0x1
commit b6d59d9f9d16faaa2d5b610ac7b0cac9c50bc0a4
6 changes: 2 additions & 4 deletions src/printer.rs
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@ use crate::{
formatting::serde_json_format,
formatting::{get_json_formatter, Highlighter},
middleware::ResponseExt,
utils::{copy_largebuf, test_mode, BUFFER_SIZE},
utils::{copy_largebuf, BUFFER_SIZE},
};

const BINARY_SUPPRESSOR: &str = concat!(
@@ -345,9 +345,7 @@ impl Printer {
// even know if we're going to use HTTP/2 yet.
headers.entry(HOST).or_insert_with(|| {
// Added at https://github.com/hyperium/hyper-util/blob/53aadac50d/src/client/legacy/client.rs#L278
if test_mode() {
HeaderValue::from_str("http.mock")
} else if let Some(port) = request.url().port() {
if let Some(port) = request.url().port() {
HeaderValue::from_str(&format!("{}:{}", host, port))
} else {
HeaderValue::from_str(host)
5 changes: 1 addition & 4 deletions src/unix_socket.rs
Original file line number Diff line number Diff line change
@@ -5,7 +5,6 @@ use std::path::PathBuf;
use std::time::Instant;

use crate::middleware::{Context, Middleware, ResponseMeta};
use crate::utils::test_mode;

pub struct UnixSocket {
rt: tokio::runtime::Runtime,
@@ -84,9 +83,7 @@ fn into_async_request(mut request: Request) -> Result<http::Request<reqwest::Bod

if let Some(host) = request.url().host_str() {
http_request.headers_mut().entry(HOST).or_insert_with(|| {
if test_mode() {
HeaderValue::from_str("http.mock")
} else if let Some(port) = request.url().port() {
if let Some(port) = request.url().port() {
HeaderValue::from_str(&format!("{}:{}", host, port))
} else {
HeaderValue::from_str(host)
10 changes: 5 additions & 5 deletions tests/cases/http_unix.rs
Original file line number Diff line number Diff line change
@@ -78,7 +78,7 @@ fn redirects_stay_on_same_server() {
Accept: */*
Accept-Encoding: gzip, deflate, br, zstd
Connection: keep-alive
Host: http.mock
Host: example.com
User-Agent: xh/0.0.0 (test mode)

HTTP/1.1 302 Found
@@ -92,7 +92,7 @@ fn redirects_stay_on_same_server() {
Accept: */*
Accept-Encoding: gzip, deflate, br, zstd
Connection: keep-alive
Host: http.mock
Host: localhost:8000
User-Agent: xh/0.0.0 (test mode)

HTTP/1.1 302 Found
@@ -106,7 +106,7 @@ fn redirects_stay_on_same_server() {
Accept: */*
Accept-Encoding: gzip, deflate, br, zstd
Connection: keep-alive
Host: http.mock
Host: localhost:8000
User-Agent: xh/0.0.0 (test mode)

HTTP/1.1 200 OK
@@ -154,7 +154,7 @@ fn cookies_persist_across_redirects() {
Accept: */*
Accept-Encoding: gzip, deflate, br, zstd
Connection: keep-alive
Host: http.mock
Host: localhost:3000
User-Agent: xh/0.0.0 (test mode)

HTTP/1.1 302 Found
@@ -170,7 +170,7 @@ fn cookies_persist_across_redirects() {
Accept-Encoding: gzip, deflate, br, zstd
Connection: keep-alive
Cookie: hello=world
Host: http.mock
Host: localhost:3000
User-Agent: xh/0.0.0 (test mode)

HTTP/1.1 200 OK
52 changes: 26 additions & 26 deletions tests/cli.rs
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@ use std::time::{Duration, SystemTime, UNIX_EPOCH};

use assert_cmd::cmd::Command;
use http_body_util::BodyExt;
use indoc::indoc;
use indoc::{formatdoc, indoc};
use predicates::function::function;
use predicates::str::contains;
use reqwest::header::HeaderValue;
@@ -429,19 +429,19 @@ fn verbose() {
get_command()
.args(["--verbose", &server.base_url(), "x=y"])
.assert()
.stdout(indoc! {r#"
.stdout(formatdoc! {r#"
POST / HTTP/1.1
Accept: application/json, */*;q=0.5
Accept-Encoding: gzip, deflate, br, zstd
Connection: keep-alive
Content-Length: 9
Content-Type: application/json
Host: http.mock
Host: 127.0.0.1:{port}
User-Agent: xh/0.0.0 (test mode)

{
{{
"x": "y"
}
}}



@@ -451,7 +451,7 @@ fn verbose() {
X-Foo: Bar

a body
"#});
"#, port = server.port() });
}

#[test]
@@ -1015,12 +1015,12 @@ fn digest_auth_with_redirection() {
.arg("--verbose")
.arg(server.url("/login_page"))
.assert()
.stdout(indoc! {r#"
.stdout(formatdoc! {r#"
GET /login_page HTTP/1.1
Accept: */*
Accept-Encoding: gzip, deflate, br, zstd
Connection: keep-alive
Host: http.mock
Host: 127.0.0.1:{port}
User-Agent: xh/0.0.0 (test mode)

HTTP/1.1 401 Unauthorized
@@ -1035,7 +1035,7 @@ fn digest_auth_with_redirection() {
Accept-Encoding: gzip, deflate, br, zstd
Authorization: Digest username="ahmed", realm="[email protected]", nonce="e5051361f053723a807674177fc7022f", uri="/login_page", qop=auth, nc=00000001, cnonce="f2/wE4q74E6zIJEtWaHKaf5wv/H5QzzpXusqGemxURZJ", response="894fd5ee1dcc702df7e4a6abed37fd56", opaque="9dcf562038f1ec1c8d02f218ef0e7a4b", algorithm=MD5
Connection: keep-alive
Host: http.mock
Host: 127.0.0.1:{port}
User-Agent: xh/0.0.0 (test mode)

HTTP/1.1 302 Found
@@ -1049,15 +1049,15 @@ fn digest_auth_with_redirection() {
Accept: */*
Accept-Encoding: gzip, deflate, br, zstd
Connection: keep-alive
Host: http.mock
Host: 127.0.0.1:{port}
User-Agent: xh/0.0.0 (test mode)

HTTP/1.1 200 OK
Content-Length: 10
Date: N/A

admin page
"#});
"#, port = server.port() });

server.assert_hits(3);
}
@@ -1805,12 +1805,12 @@ fn redirect_support_utf8_location() {
get_command()
.args([&server.url("/first_page"), "--follow", "--verbose", "--all"])
.assert()
.stdout(indoc! {r#"
.stdout(formatdoc! {r#"
GET /first_page HTTP/1.1
Accept: */*
Accept-Encoding: gzip, deflate, br, zstd
Connection: keep-alive
Host: http.mock
Host: 127.0.0.1:{port}
User-Agent: xh/0.0.0 (test mode)

HTTP/1.1 302 Found
@@ -1824,15 +1824,15 @@ fn redirect_support_utf8_location() {
Accept: */*
Accept-Encoding: gzip, deflate, br, zstd
Connection: keep-alive
Host: http.mock
Host: 127.0.0.1:{port}
User-Agent: xh/0.0.0 (test mode)

HTTP/1.1 200 OK
Content-Length: 17
Date: N/A

final destination
"#});
"#, port = server.port() });
}

#[test]
@@ -2227,7 +2227,7 @@ fn can_unset_default_headers() {
Accept: */*
Accept-Encoding: gzip, deflate, br, zstd
Connection: keep-alive
Host: http.mock
Host: localhost

"#});
}
@@ -2243,7 +2243,7 @@ fn can_unset_headers() {
Accept-Encoding: gzip, deflate, br, zstd
Connection: keep-alive
Hello: world
Host: http.mock
Host: localhost
User-Agent: xh/0.0.0 (test mode)

"#});
@@ -2260,7 +2260,7 @@ fn can_set_unset_header() {
Accept-Encoding: gzip, deflate, br, zstd
Connection: keep-alive
Hello: world
Host: http.mock
Host: localhost
User-Agent: xh/0.0.0 (test mode)

"#});
@@ -2987,12 +2987,12 @@ fn print_intermediate_requests_and_responses() {
get_command()
.args([&server.url("/first_page"), "--follow", "--verbose", "--all"])
.assert()
.stdout(indoc! {r#"
.stdout(formatdoc! {r#"
GET /first_page HTTP/1.1
Accept: */*
Accept-Encoding: gzip, deflate, br, zstd
Connection: keep-alive
Host: http.mock
Host: 127.0.0.1:{port}
User-Agent: xh/0.0.0 (test mode)

HTTP/1.1 302 Found
@@ -3006,15 +3006,15 @@ fn print_intermediate_requests_and_responses() {
Accept: */*
Accept-Encoding: gzip, deflate, br, zstd
Connection: keep-alive
Host: http.mock
Host: 127.0.0.1:{port}
User-Agent: xh/0.0.0 (test mode)

HTTP/1.1 200 OK
Content-Length: 17
Date: N/A

final destination
"#});
"#, port = server.port() });
}

#[test]
@@ -3042,12 +3042,12 @@ fn history_print() {
.arg("--history-print=Hh")
.arg("--all")
.assert()
.stdout(indoc! {r#"
.stdout(formatdoc! {r#"
GET /first_page HTTP/1.1
Accept: */*
Accept-Encoding: gzip, deflate, br, zstd
Connection: keep-alive
Host: http.mock
Host: 127.0.0.1:{port}
User-Agent: xh/0.0.0 (test mode)

HTTP/1.1 302 Found
@@ -3059,15 +3059,15 @@ fn history_print() {
Accept: */*
Accept-Encoding: gzip, deflate, br, zstd
Connection: keep-alive
Host: http.mock
Host: 127.0.0.1:{port}
User-Agent: xh/0.0.0 (test mode)

HTTP/1.1 200 OK
Content-Length: 17
Date: N/A

final destination
"#});
"#, port = server.port() });
}

#[test]