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

net/http: add customization of proxy CONNECT requests #15027

Closed
AlmogBaku opened this issue Mar 30, 2016 · 5 comments
Closed

net/http: add customization of proxy CONNECT requests #15027

AlmogBaku opened this issue Mar 30, 2016 · 5 comments

Comments

@AlmogBaku
Copy link

Please answer these questions before submitting your issue. Thanks!

  1. What version of Go are you using (go version)?
    1.6
  2. What operating system and processor architecture are you using (go env)?
    darwin amd64 [os x]
  3. What did you do?
    I tried to use Proxy with a Bearer authentication method.
  4. What did you expect to see?
    Allow other authentication method than Basic HTTP
  5. What did you see instead?
    Proxy authentication is limited to Basic-HTTP-Authentication only, with user & password:
    https://github.com/golang/go/blob/master/src/net/http/transport.go#L493
  6. Suggestion
    • url.URL should allow custom authentication such as bearer
    • url.URL should provide a method that returns the "authentication header value", and do the base64 etc.
@bradfitz
Copy link
Contributor

This proposal is a little confused. It's proposing modifications to url.URL, but talking about net/http stuff. I think you're probably looking for https://godoc.org/golang.org/x/oauth2 and friends. In general, I think everything you need is already on godoc.org somewhere.

Let's discuss your actual needs on the mailing list before jumping to proposals. See https://golang.org/wiki/Questions.

@bradfitz bradfitz changed the title http/transport: add custom proxy authentication net/http: add customization of proxy CONNECT requests Mar 30, 2016
@bradfitz bradfitz reopened this Mar 30, 2016
@bradfitz bradfitz added this to the Unplanned milestone Mar 30, 2016
@mattn
Copy link
Member

mattn commented Mar 31, 2016

Well, I don't make sure but this seems not change of net/url. And maybe simply implementation of Transport.Proxy.

package main

import (
    "net/http"
    "net/url"
)

func main() {
    token := "blur"
    http.DefaultClient.Transport.(*http.Transport).Proxy = func(r *http.Request) (*url.URL, error) {
        r.Header.Add("Authorization", "Bearer " + token)
        return r.URL, nil
    }
}

@AlmogBaku
Copy link
Author

@mattn As I mentioned in the mailing-list, the problem is that when you do https, the CONNECT request wraps the original request, and there is no way to attach headers to the CONNECT req

@AlmogBaku
Copy link
Author

@bradfitz
Copy link
Contributor

This was added to Go 1.8. See https://beta.golang.org/pkg/net/http/#Transport.ProxyConnectHeader

Dup of #13290

@golang golang locked and limited conversation to collaborators Dec 15, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants