Skip to content

Commit

Permalink
Do not set Content-Type for DELETE requests
Browse files Browse the repository at this point in the history
DELETE requests, like GET requests, should not have a Content-Type
header as there will not be a request body. However, rack-test attempts
to set a Content-Type of application/x-www-form-urlencoded which messes
with some web frameworks' test suites (including my own). Instead of
trying to set a Content-Type header and request body on DELETEs, treat
them more like GET requests.

Signed-off-by: David Celis <me@davidcel.is>
  • Loading branch information
davidcelis committed Jul 27, 2015
1 parent 0cd8537 commit c1849d6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rack/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def env_for(path, env)
# Stringifying and upcasing methods has be commit upstream
env["REQUEST_METHOD"] ||= env[:method] ? env[:method].to_s.upcase : "GET"

if env["REQUEST_METHOD"] == "GET"
if ["GET", "DELETE"].include?(env["REQUEST_METHOD"])
# merge :params with the query string
if params = env[:params]
params = parse_nested_query(params) if params.is_a?(String)
Expand Down
6 changes: 6 additions & 0 deletions spec/rack/test_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,12 @@ def verb
describe "#delete" do
it_should_behave_like "any #verb methods"

it "does not set a content type" do
delete "/"

last_request.env['CONTENT_TYPE'].should be_nil
end

def verb
"delete"
end
Expand Down

0 comments on commit c1849d6

Please sign in to comment.