Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-pages.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlessio Caiazza <acaiazza@gitlab.com>2018-06-22 16:36:04 +0300
committerAlessio Caiazza <acaiazza@gitlab.com>2018-06-22 16:36:04 +0300
commitc4a419ed595281f62977fd47aa30d225c4eddb5d (patch)
treefbc33579fc6f4c4f40e864c18442364c33dc7e77
parent4a16516c0ab5742671bdf1cffc13b55a3b4a69b9 (diff)
parent27ef750e6a1053ecd23df55e690235be589f3815 (diff)
Merge branch 'feature/add-support-for-reverse-proxy' into 'master'
Add support for reverse proxy See merge request gitlab-org/gitlab-pages!99
-rw-r--r--acceptance_test.go20
-rw-r--r--app.go11
-rw-r--r--helpers_test.go13
3 files changed, 42 insertions, 2 deletions
diff --git a/acceptance_test.go b/acceptance_test.go
index e971588a..361cba68 100644
--- a/acceptance_test.go
+++ b/acceptance_test.go
@@ -553,3 +553,23 @@ func TestMultiFlagEnvironmentVariables(t *testing.T) {
assert.Equal(t, http.StatusOK, rsp.StatusCode)
}
}
+
+func TestKnownHostInReverseProxySetupReturns200(t *testing.T) {
+ skipUnlessEnabled(t)
+
+ var listeners = []ListenSpec{
+ {"proxy", "127.0.0.1", "37002"},
+ {"proxy", "::1", "37002"},
+ }
+
+ teardown := RunPagesProcess(t, *pagesBinary, listeners, "")
+ defer teardown()
+
+ for _, spec := range listeners {
+ rsp, err := GetProxiedPageFromListener(t, spec, "localhost", "group.gitlab-example.com", "project/")
+
+ require.NoError(t, err)
+ rsp.Body.Close()
+ assert.Equal(t, http.StatusOK, rsp.StatusCode)
+ }
+}
diff --git a/app.go b/app.go
index 38738960..5527d1f7 100644
--- a/app.go
+++ b/app.go
@@ -24,8 +24,11 @@ import (
"gitlab.com/gitlab-org/gitlab-pages/metrics"
)
-const xForwardedProto = "X-Forwarded-Proto"
-const xForwardedProtoHTTPS = "https"
+const (
+ xForwardedProto = "X-Forwarded-Proto"
+ xForwardedHost = "X-Forwarded-Host"
+ xForwardedProtoHTTPS = "https"
+)
var (
corsHandler = cors.New(cors.Options{AllowedMethods: []string{"GET"}})
@@ -158,6 +161,10 @@ func (a *theApp) ServeProxy(ww http.ResponseWriter, r *http.Request) {
forwardedProto := r.Header.Get(xForwardedProto)
https := forwardedProto == xForwardedProtoHTTPS
+ if forwardedHost := r.Header.Get(xForwardedHost); forwardedHost != "" {
+ r.Host = forwardedHost
+ }
+
a.serveContent(ww, r, https)
}
diff --git a/helpers_test.go b/helpers_test.go
index e853e1c4..ccbbb6e3 100644
--- a/helpers_test.go
+++ b/helpers_test.go
@@ -259,6 +259,19 @@ func GetPageFromListener(t *testing.T, spec ListenSpec, host, urlsuffix string)
return DoPagesRequest(t, req)
}
+func GetProxiedPageFromListener(t *testing.T, spec ListenSpec, host, xForwardedHost, urlsuffix string) (*http.Response, error) {
+ url := spec.URL(urlsuffix)
+ req, err := http.NewRequest("GET", url, nil)
+ if err != nil {
+ return nil, err
+ }
+
+ req.Host = host
+ req.Header.Set("X-Forwarded-Host", xForwardedHost)
+
+ return DoPagesRequest(t, req)
+}
+
func DoPagesRequest(t *testing.T, req *http.Request) (*http.Response, error) {
t.Logf("curl -X %s -H'Host: %s' %s", req.Method, req.Host, req.URL)