-
Notifications
You must be signed in to change notification settings - Fork 101
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
ducaale
wants to merge
26
commits into
master
Choose a base branch
from
http-over-unix-socket
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
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 aa8fbf5
support http over unix domain sockets
ducaale fe56317
implement test server for http_unix
ducaale 531dba9
add initial tests for http_unix
ducaale bf4b1b8
fix clippy warnings
ducaale 80242c2
disable http_unix tests in windows
ducaale 8cee2fe
add middleware for managing cookies
ducaale 652e3df
add test for cookies
ducaale b6d59d9
avoid mocking host header
ducaale cb8d396
use shortened version of cfg unix check
ducaale c7fb645
throw an error if unix-socket used in unsupported os
ducaale e0791b3
provide complete example for unix-socket usage
ducaale f09a191
fix missing import
ducaale 67730e1
check that host header is passed
ducaale de52108
Merge branch 'master' into http-over-unix-socket
ducaale 0a80407
store unix_client in ClientWithMiddleware
ducaale 3d887f0
Merge branch 'master' into http-over-unix-socket
ducaale 2eb6367
Merge branch 'master' into http-over-unix-socket
ducaale 31c4420
warn or error if unix-socket used with unsupported option
ducaale 8bcbb0d
disable failing badssl.com tests
ducaale d601946
implement read timeout for unix_socket requests
ducaale c84e8ef
implement connect timeout for unix_socket requests
ducaale e362e7f
switch from read timeout to total timeout
ducaale 92df488
revert disabling badssl tests
ducaale bd8dbdd
Merge branch 'master' into http-over-unix-socket
ducaale 7db9b38
Merge branch 'master' into http-over-unix-socket
ducaale File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,44 @@ | ||
use std::sync::Arc; | ||
|
||
use anyhow::Result; | ||
use reqwest::{ | ||
blocking::{Request, Response}, | ||
cookie::CookieStore, | ||
header, | ||
}; | ||
|
||
use crate::middleware::{Context, Middleware}; | ||
|
||
pub struct CookieMiddleware<T>(Arc<T>); | ||
|
||
impl<T> CookieMiddleware<T> { | ||
pub fn new(cookie_jar: Arc<T>) -> Self { | ||
CookieMiddleware(cookie_jar) | ||
} | ||
} | ||
|
||
impl<T: CookieStore> Middleware for CookieMiddleware<T> { | ||
fn handle(&mut self, mut ctx: Context, mut request: Request) -> Result<Response> { | ||
let url = request.url().clone(); | ||
|
||
if let Some(header) = self.0.cookies(&url) { | ||
request | ||
.headers_mut() | ||
.entry(header::COOKIE) | ||
.or_insert(header); | ||
} | ||
|
||
let response = self.next(&mut ctx, request)?; | ||
|
||
let mut cookies = response | ||
.headers() | ||
.get_all(header::SET_COOKIE) | ||
.iter() | ||
.peekable(); | ||
if cookies.peek().is_some() { | ||
self.0.set_cookies(&mut cookies, &url); | ||
} | ||
|
||
Ok(response) | ||
} | ||
} |
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Many of these might plausibly appear in an alias or config file, like
--https
,--ssl
.If someone passes
--proxy
they probably made a mistake but I think the list could be shorter. Maybe a guideline could be whether the option is compatible with a normal request tohttp://127.0.0.1
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Were you thinking of silently ignoring some of the flags or maybe printing a warning?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
--https
for example doesn't force HTTPS, it just changes the default scheme of the URL. So maybe the user gets an error if they pass:/index.html
because that gets converted tohttps://localhost/index.html
and the socket doesn't support TLS, but if they use--https
with an explicithttp://localhost/index.html
then that should be perfectly fine, just like inxh --https http://127.0.0.1
the--https
flag is useless but harmless.