Skip to content
This repository has been archived by the owner on Sep 4, 2021. It is now read-only.

Commit

Permalink
pkg/httpclient: Add OAuth header to Hijacked requests
Browse files Browse the repository at this point in the history
Signed-off-by: Jonathan Rudenberg <jonathan@titanous.com>
  • Loading branch information
titanous committed Aug 10, 2020
1 parent 1ecd12c commit bcaee23
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions pkg/httpclient/json.go
Expand Up @@ -16,6 +16,7 @@ import (

"github.com/flynn/flynn/pkg/httphelper"
"github.com/flynn/flynn/pkg/stream"
"golang.org/x/oauth2"
)

type DialFunc func(network, addr string) (net.Conn, error)
Expand Down Expand Up @@ -182,6 +183,19 @@ func (c *Client) Hijack(method, path string, header http.Header, in interface{})
if err != nil {
return nil, err
}

if ot, ok := c.HTTP.Transport.(*oauth2.Transport); ok {
t, err := ot.Source.Token()
if err != nil {
return nil, &url.Error{
Op: method,
URL: path,
Err: err,
}
}
t.SetAuthHeader(req)
}

req.Header.Set("Connection", "upgrade")
res, err := clientconn.Do(req)
if err != nil && err != httputil.ErrPersistEOF {
Expand Down

0 comments on commit bcaee23

Please sign in to comment.