Commit c3447a94 authored by Jacob Vosmaer (GitLab)'s avatar Jacob Vosmaer (GitLab)

Merge branch 'unicorn-tming' into 'master'

Send timestamps when proxying

For https://gitlab.com/gitlab-com/operations/issues/264

Companion to https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/4278

See merge request !47
parents 74cf6dfc 4704ce33
package proxy
import (
"fmt"
"net/http"
"net/http/httputil"
"net/url"
"time"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/badgateway"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/helper"
......@@ -34,6 +36,7 @@ func (p *Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// Set Workhorse version
req.Header.Set("Gitlab-Workhorse", p.Version)
req.Header.Set("Gitlab-Worhorse-Proxy-Start", fmt.Sprintf("%d", time.Now().UnixNano()))
p.reverseProxy.ServeHTTP(w, &req)
}
......@@ -8,6 +8,7 @@ import (
"net/http"
"net/http/httptest"
"regexp"
"strings"
"testing"
"time"
......@@ -17,8 +18,10 @@ import (
"gitlab.com/gitlab-org/gitlab-workhorse/internal/testhelper"
)
const testVersion = "123"
func newProxy(url string, rt *badgateway.RoundTripper) *proxy.Proxy {
return proxy.NewProxy(helper.URLMustParse(url), "123", rt)
return proxy.NewProxy(helper.URLMustParse(url), testVersion, rt)
}
func TestProxyRequest(t *testing.T) {
......@@ -31,6 +34,14 @@ func TestProxyRequest(t *testing.T) {
t.Fatal("Missing custom header")
}
if h := r.Header.Get("Gitlab-Workhorse"); h != testVersion {
t.Fatalf("Missing GitLab-Workhorse header: want %q, got %q", testVersion, h)
}
if h := r.Header.Get("Gitlab-Worhorse-Proxy-Start"); !strings.HasPrefix(h, "1") {
t.Fatalf("Expect Gitlab-Worhorse-Proxy-Start to start with 1, got %q", h)
}
var body bytes.Buffer
io.Copy(&body, r.Body)
if body.String() != "REQUEST" {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment