[lxc-devel] [lxd/master] Forward user-agent and other headers on redirect
stgraber on Github
lxc-bot at linuxcontainers.org
Wed Feb 15 00:24:14 UTC 2017
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 550 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20170215/511c7642/attachment.bin>
-------------- next part --------------
From b3eaec431d4e408f106fdf310659be6496b7e790 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Tue, 14 Feb 2017 19:20:57 -0500
Subject: [PATCH] Forward user-agent and other headers on redirect
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
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 at ubuntu.com>
---
client.go | 9 +++++++++
lxd/daemon.go | 8 ++++++++
2 files changed, 17 insertions(+)
diff --git a/client.go b/client.go
index 6893165..7908ea5 100644
--- a/client.go
+++ b/client.go
@@ -278,6 +278,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)
diff --git a/lxd/daemon.go b/lxd/daemon.go
index 2de8487..36a3ae4 100644
--- a/lxd/daemon.go
+++ b/lxd/daemon.go
@@ -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
}
More information about the lxc-devel
mailing list