Skip to content

Commit

Permalink
Forward user-agent and other headers on redirect
Browse files Browse the repository at this point in the history
We don't use sensitive headers so don't need to be concerned about
crossing domain boundaries. So simply always copy all headers to
subsequent requests in the redirect chain.

Closes #2805

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
  • Loading branch information
stgraber committed Feb 25, 2017
1 parent 23fedd5 commit cb17028
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
9 changes: 9 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,15 @@ func NewClientFromInfo(info ConnectInfo) (*Client, error) {
},
}
c.Name = info.Name

// Setup redirect policy
c.Http.CheckRedirect = func(req *http.Request, via []*http.Request) error {
// Replicate the headers
req.Header = via[len(via)-1].Header

return nil
}

var err error
if strings.HasPrefix(info.RemoteConfig.Addr, "unix:") {
err = connectViaUnix(c, &info.RemoteConfig)
Expand Down
8 changes: 8 additions & 0 deletions lxd/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,14 @@ func (d *Daemon) httpClient(certificate string) (*http.Client, error) {
Transport: tr,
}

// Setup redirect policy
myhttp.CheckRedirect = func(req *http.Request, via []*http.Request) error {
// Replicate the headers
req.Header = via[len(via)-1].Header

return nil
}

return &myhttp, nil
}

Expand Down

0 comments on commit cb17028

Please sign in to comment.