Skip to content

Commit

Permalink
fix(admin) unsupported media type (415) error reported on issue #1182
Browse files Browse the repository at this point in the history
  • Loading branch information
bungle committed Dec 14, 2017
1 parent 6719051 commit 503dcc6
Show file tree
Hide file tree
Showing 3 changed files with 500 additions and 201 deletions.
28 changes: 25 additions & 3 deletions kong/api/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ local api_helpers = require "kong.api.api_helpers"


local find = string.find
local sub = string.sub


local app = lapis.Application()
Expand Down Expand Up @@ -89,10 +90,31 @@ end


app:before_filter(function(self)
if NEEDS_BODY[ngx.req.get_method()]
and not self.req.headers["content-type"] then
return responses.send_HTTP_UNSUPPORTED_MEDIA_TYPE()
if not NEEDS_BODY[ngx.req.get_method()] then
return
end

local content_type = self.req.headers["content-type"]
if not content_type then
local content_length = self.req.headers["content-length"]
if content_length == "0" then
return
end

if not content_length then
local _, err = ngx.req.socket()
if err == "no body" then
return
end
end

elseif sub(content_type, 1, 16) == "application/json" or
sub(content_type, 1, 19) == "multipart/form-data" or
sub(content_type, 1, 33) == "application/x-www-form-urlencoded" then
return
end

return responses.send_HTTP_UNSUPPORTED_MEDIA_TYPE()
end)


Expand Down
Loading

0 comments on commit 503dcc6

Please sign in to comment.