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
55c816ca
Commit
55c816ca
authored
Mar 01, 2017
by
Kamil Trzcinski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
More robust application/json matching
parent
e837d788
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
1 deletion
+25
-1
internal/builds/register.go
internal/builds/register.go
+1
-1
internal/helper/helpers.go
internal/helper/helpers.go
+5
-0
internal/helper/helpers_test.go
internal/helper/helpers_test.go
+19
-0
No files found.
internal/builds/register.go
View file @
55c816ca
...
...
@@ -58,7 +58,7 @@ func readRunnerBody(w http.ResponseWriter, r *http.Request) ([]byte, error) {
func
readRunnerRequest
(
r
*
http
.
Request
,
body
[]
byte
)
(
runnerRequest
,
error
)
{
var
runnerRequest
runnerRequest
if
r
.
Header
.
Get
(
"Content-Type"
)
!=
"application/json"
{
if
!
helper
.
IsApplicationJson
(
r
)
{
return
runnerRequest
,
errors
.
New
(
"invalid content-type received"
)
}
...
...
internal/helper/helpers.go
View file @
55c816ca
...
...
@@ -170,6 +170,11 @@ func IsContentType(expected, actual string) bool {
return
err
==
nil
&&
parsed
==
expected
}
func
IsApplicationJson
(
r
*
http
.
Request
)
bool
{
contentType
:=
r
.
Header
.
Get
(
"Content-Type"
)
return
IsContentType
(
"application/json"
,
contentType
)
}
func
ReadRequestBody
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
,
maxBodySize
int64
)
([]
byte
,
error
)
{
limitedBody
:=
http
.
MaxBytesReader
(
w
,
r
.
Body
,
maxBodySize
)
defer
limitedBody
.
Close
()
...
...
internal/helper/helpers_test.go
View file @
55c816ca
...
...
@@ -101,3 +101,22 @@ func TestCloneRequestWithBody(t *testing.T) {
t
.
Fatal
(
"Expected the readed body to be the same as passed to function"
)
}
}
func
TestApplicationJson
(
t
*
testing
.
T
)
{
req
:=
httptest
.
NewRequest
(
"POST"
,
"/test"
,
nil
)
req
.
Header
.
Set
(
"Content-Type"
,
"application/json"
)
if
!
IsApplicationJson
(
req
)
{
t
.
Fatalf
(
"Expected to match 'application/json' as 'application/json'"
)
}
req
.
Header
.
Set
(
"Content-Type"
,
"application/json; charset=utf-8"
)
if
!
IsApplicationJson
(
req
)
{
t
.
Fatalf
(
"Expected to match 'application/json; charset=utf-8' as 'application/json'"
)
}
req
.
Header
.
Set
(
"Content-Type"
,
"text/plain"
)
if
IsApplicationJson
(
req
)
{
t
.
Fatalf
(
"Expected not to match 'text/plain' as 'application/json'"
)
}
}
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