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 package proxy
import ( import (
"fmt"
"net/http" "net/http"
"net/http/httputil" "net/http/httputil"
"net/url" "net/url"
"time"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/badgateway" "gitlab.com/gitlab-org/gitlab-workhorse/internal/badgateway"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/helper" "gitlab.com/gitlab-org/gitlab-workhorse/internal/helper"
...@@ -34,6 +36,7 @@ func (p *Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request) { ...@@ -34,6 +36,7 @@ func (p *Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// Set Workhorse version // Set Workhorse version
req.Header.Set("Gitlab-Workhorse", p.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) p.reverseProxy.ServeHTTP(w, &req)
} }
...@@ -8,6 +8,7 @@ import ( ...@@ -8,6 +8,7 @@ import (
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
"regexp" "regexp"
"strings"
"testing" "testing"
"time" "time"
...@@ -17,8 +18,10 @@ import ( ...@@ -17,8 +18,10 @@ import (
"gitlab.com/gitlab-org/gitlab-workhorse/internal/testhelper" "gitlab.com/gitlab-org/gitlab-workhorse/internal/testhelper"
) )
const testVersion = "123"
func newProxy(url string, rt *badgateway.RoundTripper) *proxy.Proxy { 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) { func TestProxyRequest(t *testing.T) {
...@@ -31,6 +34,14 @@ func TestProxyRequest(t *testing.T) { ...@@ -31,6 +34,14 @@ func TestProxyRequest(t *testing.T) {
t.Fatal("Missing custom header") 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 var body bytes.Buffer
io.Copy(&body, r.Body) io.Copy(&body, r.Body)
if body.String() != "REQUEST" { 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