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
b03e9b9f
Commit
b03e9b9f
authored
Jan 19, 2017
by
Nick Thomas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add helper.IsContentType and use it everywhere
parent
2de1f1e3
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
9 additions
and
7 deletions
+9
-7
internal/api/api.go
internal/api/api.go
+1
-3
internal/api/block.go
internal/api/block.go
+1
-1
internal/helper/helpers.go
internal/helper/helpers.go
+6
-0
internal/upstream/routes.go
internal/upstream/routes.go
+1
-3
No files found.
internal/api/api.go
View file @
b03e9b9f
...
...
@@ -6,7 +6,6 @@ import (
"fmt"
"io"
"io/ioutil"
"mime"
"net/http"
"net/url"
"strconv"
...
...
@@ -288,6 +287,5 @@ func bufferResponse(r io.Reader) (*bytes.Buffer, error) {
}
func
validResponseContentType
(
resp
*
http
.
Response
)
bool
{
parsed
,
_
,
err
:=
mime
.
ParseMediaType
(
resp
.
Header
.
Get
(
"Content-Type"
))
return
err
==
nil
&&
parsed
==
ResponseContentType
return
helper
.
IsContentType
(
ResponseContentType
,
resp
.
Header
.
Get
(
"Content-Type"
))
}
internal/api/block.go
View file @
b03e9b9f
...
...
@@ -44,7 +44,7 @@ func (b *blocker) WriteHeader(status int) {
return
}
if
b
.
Header
()
.
Get
(
"Content-Type"
)
==
ResponseContentType
{
if
helper
.
IsContentType
(
ResponseContentType
,
b
.
Header
()
.
Get
(
"Content-Type"
))
{
b
.
status
=
500
b
.
Header
()
.
Del
(
"Content-Length"
)
b
.
hijacked
=
true
...
...
internal/helper/helpers.go
View file @
b03e9b9f
...
...
@@ -3,6 +3,7 @@ package helper
import
(
"errors"
"log"
"mime"
"net"
"net/http"
"net/url"
...
...
@@ -160,3 +161,8 @@ func SetForwardedFor(newHeaders *http.Header, originalRequest *http.Request) {
newHeaders
.
Set
(
"X-Forwarded-For"
,
header
)
}
}
func
IsContentType
(
expected
,
actual
string
)
bool
{
parsed
,
_
,
err
:=
mime
.
ParseMediaType
(
actual
)
return
err
==
nil
&&
parsed
==
expected
}
internal/upstream/routes.go
View file @
b03e9b9f
package
upstream
import
(
"mime"
"net/http"
"path"
"regexp"
...
...
@@ -67,8 +66,7 @@ func wsRoute(regexpStr string, handler http.Handler, matchers ...matcherFunc) ro
// Creates matcherFuncs for a particular content type.
func
isContentType
(
contentType
string
)
func
(
*
http
.
Request
)
bool
{
return
func
(
r
*
http
.
Request
)
bool
{
parsed
,
_
,
err
:=
mime
.
ParseMediaType
(
r
.
Header
.
Get
(
"Content-Type"
))
return
err
==
nil
&&
contentType
==
parsed
return
helper
.
IsContentType
(
contentType
,
r
.
Header
.
Get
(
"Content-Type"
))
}
}
...
...
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