Skip to content

Commit

Permalink
Merge pull request #151 from nono/fix-content-type-with-charset
Browse files Browse the repository at this point in the history
Accept application/json; charset=utf-8 for /auth/register
  • Loading branch information
aenario authored Dec 15, 2016
2 parents 7e9c03f + b20d273 commit baae195
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 5 additions & 1 deletion web/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,11 @@ func checkRedirectParam(c echo.Context, defaultRedirect string) (string, error)

func registerClient(c echo.Context) error {
// TODO add rate-limiting to prevent DOS attacks
if c.Request().Header.Get("Content-Type") != "application/json" {
contentType := c.Request().Header.Get("Content-Type")
if contentType != "" {
contentType = strings.Split(contentType, ";")[0]
}
if contentType != "application/json" {
return c.JSON(http.StatusBadRequest, echo.Map{
"error": "bad_content_type",
})
Expand Down
2 changes: 1 addition & 1 deletion web/auth/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -914,7 +914,7 @@ func postJSON(u string, v echo.Map) (*http.Response, error) {
body, _ := json.Marshal(v)
req, _ := http.NewRequest("POST", ts.URL+u, bytes.NewBuffer(body))
req.Host = domain
req.Header.Add("Content-Type", "application/json")
req.Header.Add("Content-Type", "application/json; charset=utf-8")
req.Header.Add("Accept", "application/json")
return client.Do(req)
}
Expand Down

0 comments on commit baae195

Please sign in to comment.