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

Added proxy from env support #885

Merged
merged 4 commits into from
Oct 25, 2020
Merged

Conversation

mkorolyov
Copy link
Contributor

Added support for default unix proxy config via envs:

  • HTTP_PROXY
  • HTTPS_PROXY
  • NO_PROXY

@mkorolyov
Copy link
Contributor Author

@valyala Hi, pls take a look

// c := &fasthttp.Client{
// Dial: FasthttpProxyHTTPDialer(),
// }
func FasthttpProxyHTTPDialer() fasthttp.DialFunc {
Copy link
Collaborator

Choose a reason for hiding this comment

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

hey! first of all, thanks for your contribution and welcome!

I think we can drop FasthttpProxy prefix from function names, as we already have that in the package name. Also, as we are trying to keep fasthttp as minimalistic as possible, this package looks like a good fit for an addon package. For example, we can create github.com/fasthttp/fasthttpproxy or github.com/fasthttp/httpproxy, and put it there. This would allow us to keep a smaller api footprint. What you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @kirillDanshin !

Added FasthttpProxy prefix to be consistent with current naming in the same package.

I'm ok to move the proxy to the addon. Could you pls create github.com/fasthttp/fasthttpproxy and i will open a merge request there?

I would choose the github.com/fasthttp/fasthttpproxy to distinguis between fasthttp proxy and x/net/httpproxy packets, WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@kirillDanshin Could you pls create the repo for this addon? i will move MR there.

Copy link
Collaborator

Choose a reason for hiding this comment

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

We already have the other proxy code in this repo with similar naming. I don't see why we shouldn't add this one either.
And since it's in a different package it doesn't increase the API footprint of the fasthttp itself.
Moving this code and the other proxy code to github.com/fasthttp/fasthttpproxy sounds nice but I feel like it's a v2 thing when we can introduce breaking changes.


return func(addr string) (net.Conn, error) {

proxyURL, err := proxier(&url.URL{Host: addr})
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm wondering if Scheme should be set to https here if the port is 443?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Did you test this code? Not setting Scheme makes this always return nil.
See: https://github.com/golang/net/blob/08b38378de702b893ee869b94b32f833e2933bd2/http/httpproxy/proxy.go#L129-L138

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@erikdubbelboer Hi! thanks for the review. You are pointing to the outdated version of the x/net/httpproxy.
here is which one is currently used: https://github.com/golang/net/blob/627f9648deb96c27737b83199d44bb5c1010cbcf/http/httpproxy/proxy.go#L130-L138

authBarriersLock := sync.RWMutex{}

return func(addr string) (net.Conn, error) {

Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change

@erikdubbelboer erikdubbelboer merged commit 4eac1ae into valyala:master Oct 25, 2020
@erikdubbelboer
Copy link
Collaborator

Thanks!

@mkorolyov mkorolyov deleted the env-proxy branch October 26, 2020 10:45
@mkorolyov
Copy link
Contributor Author

@erikdubbelboer Hi! Why this MR was merged? There are still where open questions on the naming, etc? I agree with v2 for package as the way to go. I could prepare the merge request if it is still actual?

@erikdubbelboer
Copy link
Collaborator

@mkorolyov the pull request was good as. This way the naming matches the other functions in that subpackage. When I commented about v2 I meant if we ever release a v2 version of fasthttp with backwards incompatible changes, not a v2 of the fasthttpproxy subpackage.

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.

3 participants