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
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-workhorse
Commits
1913c7d9
Commit
1913c7d9
authored
Nov 22, 2016
by
Nick Thomas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Avoid setting multiple values for certain headers
parent
b598d290
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
48 additions
and
13 deletions
+48
-13
internal/git/archive.go
internal/git/archive.go
+5
-5
internal/git/archive_test.go
internal/git/archive_test.go
+27
-0
internal/git/git-http.go
internal/git/git-http.go
+4
-4
internal/staticpages/servefile_test.go
internal/staticpages/servefile_test.go
+1
-1
internal/testhelper/testhelper.go
internal/testhelper/testhelper.go
+11
-3
No files found.
internal/git/archive.go
View file @
1913c7d9
...
...
@@ -138,14 +138,14 @@ func (a *archive) Inject(w http.ResponseWriter, r *http.Request, sendData string
func
setArchiveHeaders
(
w
http
.
ResponseWriter
,
format
string
,
archiveFilename
string
)
{
w
.
Header
()
.
Del
(
"Content-Length"
)
w
.
Header
()
.
Add
(
"Content-Disposition"
,
fmt
.
Sprintf
(
`attachment; filename="%s"`
,
archiveFilename
))
w
.
Header
()
.
Set
(
"Content-Disposition"
,
fmt
.
Sprintf
(
`attachment; filename="%s"`
,
archiveFilename
))
if
format
==
"zip"
{
w
.
Header
()
.
Add
(
"Content-Type"
,
"application/zip"
)
w
.
Header
()
.
Set
(
"Content-Type"
,
"application/zip"
)
}
else
{
w
.
Header
()
.
Add
(
"Content-Type"
,
"application/octet-stream"
)
w
.
Header
()
.
Set
(
"Content-Type"
,
"application/octet-stream"
)
}
w
.
Header
()
.
Add
(
"Content-Transfer-Encoding"
,
"binary"
)
w
.
Header
()
.
Add
(
"Cache-Control"
,
"private"
)
w
.
Header
()
.
Set
(
"Content-Transfer-Encoding"
,
"binary"
)
w
.
Header
()
.
Set
(
"Cache-Control"
,
"private"
)
}
func
parseArchiveFormat
(
format
string
)
(
*
exec
.
Cmd
,
string
)
{
...
...
internal/git/archive_test.go
View file @
1913c7d9
...
...
@@ -2,7 +2,10 @@ package git
import
(
"io/ioutil"
"net/http/httptest"
"testing"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/testhelper"
)
func
TestParseBasename
(
t
*
testing
.
T
)
{
...
...
@@ -42,3 +45,27 @@ func TestFinalizeArchive(t *testing.T) {
t
.
Fatalf
(
"expected nil from finalizeCachedArchive, received %v"
,
err
)
}
}
func
TestSetArchiveHeaders
(
t
*
testing
.
T
)
{
for
_
,
testCase
:=
range
[]
struct
{
in
,
out
string
}{
{
"zip"
,
"application/zip"
},
{
"zippy"
,
"application/octet-stream"
},
{
"rezip"
,
"application/octet-stream"
},
{
"_anything_"
,
"application/octet-stream"
},
}
{
w
:=
httptest
.
NewRecorder
()
// These should be replaced, not appended to
w
.
Header
()
.
Set
(
"Content-Type"
,
"test"
)
w
.
Header
()
.
Set
(
"Content-Length"
,
"test"
)
w
.
Header
()
.
Set
(
"Content-Disposition"
,
"test"
)
w
.
Header
()
.
Set
(
"Cache-Control"
,
"test"
)
setArchiveHeaders
(
w
,
testCase
.
in
,
"filename"
)
testhelper
.
AssertResponseHeader
(
t
,
w
,
"Content-Type"
,
testCase
.
out
)
testhelper
.
AssertResponseHeader
(
t
,
w
,
"Content-Length"
)
testhelper
.
AssertResponseHeader
(
t
,
w
,
"Content-Disposition"
,
`attachment; filename="filename"`
)
testhelper
.
AssertResponseHeader
(
t
,
w
,
"Cache-Control"
,
"private"
)
}
}
internal/git/git-http.go
View file @
1913c7d9
...
...
@@ -77,8 +77,8 @@ func handleGetInfoRefs(w http.ResponseWriter, r *http.Request, a *api.Response)
defer
helper
.
CleanUpProcessGroup
(
cmd
)
// Ensure brute force subprocess clean-up
// Start writing the response
w
.
Header
()
.
Add
(
"Content-Type"
,
fmt
.
Sprintf
(
"application/x-%s-advertisement"
,
rpc
))
w
.
Header
()
.
Add
(
"Cache-Control"
,
"no-cache"
)
w
.
Header
()
.
Set
(
"Content-Type"
,
fmt
.
Sprintf
(
"application/x-%s-advertisement"
,
rpc
))
w
.
Header
()
.
Set
(
"Cache-Control"
,
"no-cache"
)
w
.
WriteHeader
(
200
)
// Don't bother with HTTP 500 from this point on, just return
if
err
:=
pktLine
(
w
,
fmt
.
Sprintf
(
"# service=%s
\n
"
,
rpc
));
err
!=
nil
{
helper
.
LogError
(
r
,
fmt
.
Errorf
(
"handleGetInfoRefs: pktLine: %v"
,
err
))
...
...
@@ -164,8 +164,8 @@ func handlePostRPC(w http.ResponseWriter, r *http.Request, a *api.Response) {
r
.
Body
.
Close
()
// Start writing the response
w
.
Header
()
.
Add
(
"Content-Type"
,
fmt
.
Sprintf
(
"application/x-%s-result"
,
action
))
w
.
Header
()
.
Add
(
"Cache-Control"
,
"no-cache"
)
w
.
Header
()
.
Set
(
"Content-Type"
,
fmt
.
Sprintf
(
"application/x-%s-result"
,
action
))
w
.
Header
()
.
Set
(
"Cache-Control"
,
"no-cache"
)
w
.
WriteHeader
(
200
)
// Don't bother with HTTP 500 from this point on, just return
// This io.Copy may take a long time, both for Git push and pull.
...
...
internal/staticpages/servefile_test.go
View file @
1913c7d9
...
...
@@ -116,7 +116,7 @@ func testServingThePregzippedFile(t *testing.T, enableGzip bool) {
}
}
else
{
testhelper
.
AssertResponseCode
(
t
,
w
,
200
)
testhelper
.
AssertResponseHeader
(
t
,
w
,
"Content-Encoding"
,
""
)
testhelper
.
AssertResponseHeader
(
t
,
w
,
"Content-Encoding"
)
if
w
.
Body
.
String
()
!=
fileContent
{
t
.
Error
(
"We should serve the file: "
,
w
.
Body
.
String
())
}
...
...
internal/testhelper/testhelper.go
View file @
1913c7d9
...
...
@@ -63,9 +63,17 @@ func AssertResponseBody(t *testing.T, response *httptest.ResponseRecorder, expec
}
}
func
AssertResponseHeader
(
t
*
testing
.
T
,
response
*
httptest
.
ResponseRecorder
,
header
string
,
expectedValue
string
)
{
if
response
.
Header
()
.
Get
(
header
)
!=
expectedValue
{
t
.
Fatalf
(
"for HTTP request expected to receive the header %q with %q, got %q"
,
header
,
expectedValue
,
response
.
Header
()
.
Get
(
header
))
func
AssertResponseHeader
(
t
*
testing
.
T
,
w
http
.
ResponseWriter
,
header
string
,
expected
...
string
)
{
actual
:=
w
.
Header
()[
http
.
CanonicalHeaderKey
(
header
)]
if
len
(
expected
)
!=
len
(
actual
)
{
t
.
Fatalf
(
"for HTTP request expected to receive the header %q with %+v, got %+v"
,
header
,
expected
,
actual
)
}
for
i
,
value
:=
range
expected
{
if
value
!=
actual
[
i
]
{
t
.
Fatalf
(
"for HTTP request expected to receive the header %q with %+v, got %+v"
,
header
,
expected
,
actual
)
}
}
}
...
...
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