Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
46680f42
Commit
46680f42
authored
Feb 11, 2016
by
Jacob Vosmaer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Configure sendfile and injecters in routes.go
parent
f819a3c5
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
95 additions
and
37 deletions
+95
-37
internal/lfs/lfs.go
internal/lfs/lfs.go
+2
-3
internal/proxy/proxy.go
internal/proxy/proxy.go
+1
-4
internal/senddata/injecter.go
internal/senddata/injecter.go
+1
-1
internal/senddata/senddata.go
internal/senddata/senddata.go
+69
-0
internal/sendfile/sendfile.go
internal/sendfile/sendfile.go
+12
-25
internal/upstream/routes.go
internal/upstream/routes.go
+10
-4
No files found.
internal/lfs/lfs.go
View file @
46680f42
...
...
@@ -7,7 +7,6 @@ package lfs
import
(
"../api"
"../helper"
"../proxy"
"bytes"
"crypto/sha256"
"encoding/hex"
...
...
@@ -20,8 +19,8 @@ import (
"path/filepath"
)
func
PutStore
(
a
*
api
.
API
,
p
*
proxy
.
Proxy
)
http
.
Handler
{
return
lfsAuthorizeHandler
(
a
,
handleStoreLfsObject
(
p
))
func
PutStore
(
a
*
api
.
API
,
h
http
.
Handler
)
http
.
Handler
{
return
lfsAuthorizeHandler
(
a
,
handleStoreLfsObject
(
h
))
}
func
lfsAuthorizeHandler
(
myAPI
*
api
.
API
,
handleFunc
api
.
HandleFunc
)
http
.
Handler
{
...
...
internal/proxy/proxy.go
View file @
46680f42
...
...
@@ -3,7 +3,6 @@ package proxy
import
(
"../badgateway"
"../helper"
"../inject"
"net/http"
"net/http/httputil"
"net/url"
...
...
@@ -34,8 +33,6 @@ func (p *Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// Set Workhorse version
req
.
Header
.
Set
(
"Gitlab-Workhorse"
,
p
.
Version
)
rw
:=
inject
.
NewSendFileResponseWriter
(
w
,
&
req
)
defer
rw
.
Flush
()
p
.
reverseProxy
.
ServeHTTP
(
&
r
w
,
&
req
)
p
.
reverseProxy
.
ServeHTTP
(
w
,
&
req
)
}
internal/senddata/injecter.go
View file @
46680f42
...
...
@@ -14,7 +14,7 @@ type Injecter interface {
type
Prefix
string
const
Header
=
"Gitlab-Workhorse-Send-Data"
const
Header
Key
=
"Gitlab-Workhorse-Send-Data"
func
(
p
Prefix
)
Match
(
s
string
)
bool
{
return
strings
.
HasPrefix
(
s
,
string
(
p
))
...
...
internal/senddata/senddata.go
0 → 100644
View file @
46680f42
package
senddata
import
(
"net/http"
)
type
sendDataResponseWriter
struct
{
rw
http
.
ResponseWriter
status
int
hijacked
bool
req
*
http
.
Request
injecters
[]
Injecter
}
func
SendData
(
h
http
.
Handler
,
injecters
...
Injecter
)
http
.
Handler
{
return
http
.
HandlerFunc
(
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
s
:=
sendDataResponseWriter
{
rw
:
w
,
req
:
r
,
injecters
:
injecters
,
}
defer
s
.
Flush
()
h
.
ServeHTTP
(
&
s
,
r
)
})
}
func
(
s
*
sendDataResponseWriter
)
Header
()
http
.
Header
{
return
s
.
rw
.
Header
()
}
func
(
s
*
sendDataResponseWriter
)
Write
(
data
[]
byte
)
(
n
int
,
err
error
)
{
if
s
.
status
==
0
{
s
.
WriteHeader
(
http
.
StatusOK
)
}
if
s
.
hijacked
{
return
}
return
s
.
rw
.
Write
(
data
)
}
func
(
s
*
sendDataResponseWriter
)
WriteHeader
(
status
int
)
{
if
s
.
status
!=
0
{
return
}
s
.
status
=
status
if
s
.
status
!=
http
.
StatusOK
{
s
.
rw
.
WriteHeader
(
s
.
status
)
return
}
if
header
:=
s
.
Header
()
.
Get
(
HeaderKey
);
header
!=
""
{
s
.
Header
()
.
Del
(
HeaderKey
)
for
_
,
injecter
:=
range
s
.
injecters
{
if
injecter
.
Match
(
header
)
{
s
.
hijacked
=
true
injecter
.
Inject
(
s
.
rw
,
s
.
req
,
header
)
return
}
}
}
s
.
rw
.
WriteHeader
(
s
.
status
)
return
}
func
(
s
*
sendDataResponseWriter
)
Flush
()
{
s
.
WriteHeader
(
http
.
StatusOK
)
}
internal/
inject
/sendfile.go
→
internal/
sendfile
/sendfile.go
View file @
46680f42
...
...
@@ -4,12 +4,10 @@ via the X-Sendfile mechanism. All that is needed in the Rails code is the
'send_file' method.
*/
package
inject
package
sendfile
import
(
"../git"
"../helper"
"../senddata"
"log"
"net/http"
)
...
...
@@ -23,14 +21,17 @@ type sendFileResponseWriter struct {
req
*
http
.
Request
}
func
NewSendFileResponseWriter
(
rw
http
.
ResponseWriter
,
req
*
http
.
Request
)
sendFileResponseWriter
{
s
:=
sendFileResponseWriter
{
func
SendFile
(
h
http
.
Handler
)
http
.
Handler
{
return
http
.
HandlerFunc
(
func
(
rw
http
.
ResponseWriter
,
req
*
http
.
Request
)
{
s
:=
&
sendFileResponseWriter
{
rw
:
rw
,
req
:
req
,
}
// Advertise to upstream (Rails) that we support X-Sendfile
req
.
Header
.
Set
(
"X-Sendfile-Type"
,
"X-Sendfile"
)
return
s
defer
s
.
Flush
()
h
.
ServeHTTP
(
s
,
req
)
})
}
func
(
s
*
sendFileResponseWriter
)
Header
()
http
.
Header
{
...
...
@@ -68,20 +69,6 @@ func (s *sendFileResponseWriter) WriteHeader(status int) {
return
}
if
header
:=
s
.
Header
()
.
Get
(
senddata
.
Header
);
header
!=
""
{
s
.
Header
()
.
Del
(
senddata
.
Header
)
for
_
,
handler
:=
range
[]
senddata
.
Injecter
{
git
.
SendBlob
,
git
.
SendArchive
,
}
{
if
handler
.
Match
(
header
)
{
s
.
hijacked
=
true
handler
.
Inject
(
s
.
rw
,
s
.
req
,
header
)
return
}
}
}
s
.
rw
.
WriteHeader
(
s
.
status
)
return
}
...
...
internal/upstream/routes.go
View file @
46680f42
...
...
@@ -6,6 +6,8 @@ import (
"../git"
"../lfs"
proxypkg
"../proxy"
"../senddata"
"../sendfile"
"../staticpages"
"net/http"
"regexp"
...
...
@@ -37,10 +39,14 @@ func (u *Upstream) configureRoutes() {
u
.
RoundTripper
,
)
static
:=
&
staticpages
.
Static
{
u
.
DocumentRoot
}
proxy
:=
proxypkg
.
NewProxy
(
proxy
:=
senddata
.
SendData
(
sendfile
.
SendFile
(
proxypkg
.
NewProxy
(
u
.
Backend
,
u
.
Version
,
u
.
RoundTripper
,
)),
git
.
SendArchive
,
git
.
SendBlob
,
)
u
.
Routes
=
[]
route
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment