Commit a6655446 authored by Jacob Vosmaer's avatar Jacob Vosmaer

Use some more constants

parent a3fc1506
...@@ -14,7 +14,10 @@ import ( ...@@ -14,7 +14,10 @@ import (
"strings" "strings"
) )
const sendDataHeader = "Gitlab-Workhorse-Send-Data" const (
sendDataResponseHeader = "Gitlab-Workhorse-Send-Data"
sendFileResponseHeader = "X-Sendfile"
)
type sendFileResponseWriter struct { type sendFileResponseWriter struct {
rw http.ResponseWriter rw http.ResponseWriter
...@@ -28,6 +31,7 @@ func NewSendFileResponseWriter(rw http.ResponseWriter, req *http.Request) sendFi ...@@ -28,6 +31,7 @@ func NewSendFileResponseWriter(rw http.ResponseWriter, req *http.Request) sendFi
rw: rw, rw: rw,
req: req, req: req,
} }
// Advertise to upstream (Rails) that we support X-Sendfile
req.Header.Set("X-Sendfile-Type", "X-Sendfile") req.Header.Set("X-Sendfile-Type", "X-Sendfile")
return s return s
} }
...@@ -57,8 +61,8 @@ func (s *sendFileResponseWriter) WriteHeader(status int) { ...@@ -57,8 +61,8 @@ func (s *sendFileResponseWriter) WriteHeader(status int) {
return return
} }
if file := s.Header().Get("X-Sendfile"); file != "" { if file := s.Header().Get(sendFileResponseHeader); file != "" {
s.Header().Del("X-Sendfile") s.Header().Del(sendFileResponseHeader)
// Mark this connection as hijacked // Mark this connection as hijacked
s.hijacked = true s.hijacked = true
...@@ -66,8 +70,8 @@ func (s *sendFileResponseWriter) WriteHeader(status int) { ...@@ -66,8 +70,8 @@ func (s *sendFileResponseWriter) WriteHeader(status int) {
sendFileFromDisk(s.rw, s.req, file) sendFileFromDisk(s.rw, s.req, file)
return return
} }
if sendData := s.Header().Get(sendDataHeader); strings.HasPrefix(sendData, git.SendBlobPrefix) { if sendData := s.Header().Get(sendDataResponseHeader); strings.HasPrefix(sendData, git.SendBlobPrefix) {
s.Header().Del(sendDataHeader) s.Header().Del(sendDataResponseHeader)
s.hijacked = true s.hijacked = true
git.SendBlob(s.rw, s.req, sendData) git.SendBlob(s.rw, s.req, sendData)
return return
......
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