Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-workhorse
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
0
Merge Requests
0
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
Kazuhiko Shiozaki
gitlab-workhorse
Commits
a3fc1506
Commit
a3fc1506
authored
Feb 01, 2016
by
Jacob Vosmaer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Assert internal header removal
parent
b6dcb7c8
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
9 deletions
+10
-9
internal/senddata/sendfile.go
internal/senddata/sendfile.go
+5
-8
main_test.go
main_test.go
+5
-1
No files found.
internal/senddata/sendfile.go
View file @
a3fc1506
...
@@ -14,6 +14,8 @@ import (
...
@@ -14,6 +14,8 @@ import (
"strings"
"strings"
)
)
const
sendDataHeader
=
"Gitlab-Workhorse-Send-Data"
type
sendFileResponseWriter
struct
{
type
sendFileResponseWriter
struct
{
rw
http
.
ResponseWriter
rw
http
.
ResponseWriter
status
int
status
int
...
@@ -45,13 +47,6 @@ func (s *sendFileResponseWriter) Write(data []byte) (n int, err error) {
...
@@ -45,13 +47,6 @@ func (s *sendFileResponseWriter) Write(data []byte) (n int, err error) {
}
}
func
(
s
*
sendFileResponseWriter
)
WriteHeader
(
status
int
)
{
func
(
s
*
sendFileResponseWriter
)
WriteHeader
(
status
int
)
{
// Never pass these headers to the client
defer
func
()
{
s
.
Header
()
.
Del
(
"X-Sendfile"
)
s
.
Header
()
.
Del
(
"Gitlab-Workhorse-Send-Data"
)
}()
if
s
.
status
!=
0
{
if
s
.
status
!=
0
{
return
return
}
}
...
@@ -63,6 +58,7 @@ func (s *sendFileResponseWriter) WriteHeader(status int) {
...
@@ -63,6 +58,7 @@ func (s *sendFileResponseWriter) WriteHeader(status int) {
}
}
if
file
:=
s
.
Header
()
.
Get
(
"X-Sendfile"
);
file
!=
""
{
if
file
:=
s
.
Header
()
.
Get
(
"X-Sendfile"
);
file
!=
""
{
s
.
Header
()
.
Del
(
"X-Sendfile"
)
// Mark this connection as hijacked
// Mark this connection as hijacked
s
.
hijacked
=
true
s
.
hijacked
=
true
...
@@ -70,7 +66,8 @@ func (s *sendFileResponseWriter) WriteHeader(status int) {
...
@@ -70,7 +66,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
(
"Gitlab-Workhorse-Send-Data"
);
strings
.
HasPrefix
(
sendData
,
git
.
SendBlobPrefix
)
{
if
sendData
:=
s
.
Header
()
.
Get
(
sendDataHeader
);
strings
.
HasPrefix
(
sendData
,
git
.
SendBlobPrefix
)
{
s
.
Header
()
.
Del
(
sendDataHeader
)
s
.
hijacked
=
true
s
.
hijacked
=
true
git
.
SendBlob
(
s
.
rw
,
s
.
req
,
sendData
)
git
.
SendBlob
(
s
.
rw
,
s
.
req
,
sendData
)
return
return
...
...
main_test.go
View file @
a3fc1506
...
@@ -558,10 +558,11 @@ func TestArtifactsGetSingleFile(t *testing.T) {
...
@@ -558,10 +558,11 @@ func TestArtifactsGetSingleFile(t *testing.T) {
func
TestGetGitBlob
(
t
*
testing
.
T
)
{
func
TestGetGitBlob
(
t
*
testing
.
T
)
{
blobId
:=
"50b27c6518be44c42c4d87966ae2481ce895624c"
// the LICENSE file in the test repository
blobId
:=
"50b27c6518be44c42c4d87966ae2481ce895624c"
// the LICENSE file in the test repository
blobLength
:=
1075
blobLength
:=
1075
headerKey
:=
http
.
CanonicalHeaderKey
(
"Gitlab-Workhorse-Send-Data"
)
ts
:=
testhelper
.
TestServerWithHandler
(
regexp
.
MustCompile
(
`.`
),
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
ts
:=
testhelper
.
TestServerWithHandler
(
regexp
.
MustCompile
(
`.`
),
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
responseJSON
:=
fmt
.
Sprintf
(
`{"RepoPath":"%s","BlobId":"%s"}`
,
path
.
Join
(
testRepoRoot
,
testRepo
),
blobId
)
responseJSON
:=
fmt
.
Sprintf
(
`{"RepoPath":"%s","BlobId":"%s"}`
,
path
.
Join
(
testRepoRoot
,
testRepo
),
blobId
)
encodedJSON
:=
base64
.
StdEncoding
.
EncodeToString
([]
byte
(
responseJSON
))
encodedJSON
:=
base64
.
StdEncoding
.
EncodeToString
([]
byte
(
responseJSON
))
w
.
Header
()
.
Set
(
"Gitlab-Workhorse-Send-Data"
,
"git-blob:"
+
encodedJSON
)
w
.
Header
()
.
Set
(
headerKey
,
"git-blob:"
+
encodedJSON
)
// Prevent the Go HTTP server from setting the Content-Length to 0.
// Prevent the Go HTTP server from setting the Content-Length to 0.
w
.
Header
()
.
Set
(
"Transfer-Encoding"
,
"chunked"
)
w
.
Header
()
.
Set
(
"Transfer-Encoding"
,
"chunked"
)
if
_
,
err
:=
fmt
.
Fprintf
(
w
,
"GNU General Public License"
);
err
!=
nil
{
if
_
,
err
:=
fmt
.
Fprintf
(
w
,
"GNU General Public License"
);
err
!=
nil
{
...
@@ -581,6 +582,9 @@ func TestGetGitBlob(t *testing.T) {
...
@@ -581,6 +582,9 @@ func TestGetGitBlob(t *testing.T) {
if
resp
.
StatusCode
!=
200
{
if
resp
.
StatusCode
!=
200
{
t
.
Errorf
(
"GET %q: expected 200, got %d"
,
resourcePath
,
resp
.
StatusCode
)
t
.
Errorf
(
"GET %q: expected 200, got %d"
,
resourcePath
,
resp
.
StatusCode
)
}
}
if
len
(
resp
.
Header
[
headerKey
])
!=
0
{
t
.
Fatalf
(
"Unexpected response header: %s: %q"
,
headerKey
,
resp
.
Header
.
Get
(
headerKey
))
}
body
,
err
:=
ioutil
.
ReadAll
(
resp
.
Body
)
body
,
err
:=
ioutil
.
ReadAll
(
resp
.
Body
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatal
(
err
)
t
.
Fatal
(
err
)
...
...
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