8000 Add ability to dial API via unix socket by jgold-stripe · Pull Request #3779 · cli/cli · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add ability to dial API via unix socket #3779

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

Merged
merged 4 commits into from
Jun 29, 2021
Merged

Conversation

jgold-stripe
Copy link
Contributor

This change adds the ability to route HTTP traffic over a unix domain socket. It does so by reading an optional configuration value, http_unix_socket, containing the path of the socket.

The code here is broken into some smaller changes to (hopefully) aid in its review. We first refactor NewHTTPClient to allow for error returns, and add the new http.RoundTripper implementation returned by httpunix.NewRoundTripper. Next we add configuration support for the new value http_unix_socket. Finally, we read and use this configuration value if present.

In addition to the unit tests around configuration, this change has been used by me internally in my normal work over the last few weeks.

Fixes #3268

@jgold-stripe jgold-stripe changed the title Unix Add ability to dial API via unix socket Jun 3, 2021
// which would use that non-default behavior is right here, and it doesn't
// seem worth the cognitive overhead everywhere else just to serve this one
// use case.
unixSocket, err := cfg.Get("", "http_unix_socket")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test data suggests that this should be a per-hostname setting which makes sense. However, that makes implementing this more complex -- we don't know what host a user wants to use until we have a request in hand we can extract a hostname from.

You're welcome to propose a refactor that will make using the socket hostname aware; otherwise, we can discuss the trade-off of making this a global setting instead of a per-host one.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good point -- thanks for raising it. How would you feel about me changing things to make it a global setting? Making it per-host does seem ideal, but I suspect it is a non-trivial refactor to get us into that position first. @mislav mentioned some work may be ongoing to that effect, but I wasn't clear what it is or where it is tracked (discussion).

In my experience at least, having it on the global config is still valuable. In fact that's how I am using it, as the code here indicates, and it seems like having a global config to start and later adding per-host overrides would be possible and let us make partial progress now. Would you be open to an update in which I make the test code align with this, and support it only at the host level?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm totally fine with this being global to start 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I backed out the test assertions which suggested there was any meaning to this value on a host-level :)

One thing that I can't tell for sure is whether config entries are supposed to be specifically marked somehow as "config-only", "host-only", or "cascading", etc. I don't think there is, and IIUC the config schema itself doesn't enforce where a config can be found -- that is enforced by convention only. If I overlooked it though please let me know.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, there is no way to be explicit about those config categories, unfortunately -- it's convention and documentation right now.

Copy link
Contributor
@vilmibm vilmibm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this and for your patience.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow use of a unix-socket forward proxy
3 participants
0