seancribbs/webmachine-ruby — Issue #28: Rack adapter ignores content-type header
Author: pawelpacana
Created: 2012-01-18 15:43:32+00:00
State: open

This happens because Rack's `env` hash is parsed using `Webmachine::Headers.from_cgi` and this only rewrites headers that are prefixed with `HTTP`: https://github.com/seancribbs/webmachine-ruby/blob/master/lib/webmachine/headers.rb#L8

Below is a complete `env` hash from curl request received by webmachine running on rack adapter just before `.from_cgi`:

```ruby
{
"CONTENT_TYPE"=>"application/json",
"GATEWAY_INTERFACE"=>"CGI/1.1",
"PATH_INFO"=>"/notices",
"QUERY_STRING"=>"",
"REMOTE_ADDR"=>"127.0.0.1",
"REMOTE_HOST"=>"localhost",
"REQUEST_METHOD"=>"PUT",
"REQUEST_URI"=>"http://localhost:9292/notices",
"SCRIPT_NAME"=>"",
"SERVER_NAME"=>"localhost",
"SERVER_PORT"=>"9292",
"SERVER_PROTOCOL"=>"HTTP/1.1",
"SERVER_SOFTWARE"=>"WEBrick/1.3.1 (Ruby/1.9.3/2011-10-30)",
"HTTP_USER_AGENT"=>
"curl/7.21.4 (universal-apple-darwin11.0) libcurl/7.21.4 OpenSSL/0.9.8r zlib/1.2.5",
"HTTP_HOST"=>"localhost:9292",
"HTTP_ACCEPT"=>"*/*",
"rack.version"=>[1, 1],
"rack.input"=>
#>,
"rack.errors"=>
#>>,
"rack.multithread"=>true,
"rack.multiprocess"=>false,
"rack.run_once"=>false,
"rack.url_scheme"=>"http",
"HTTP_VERSION"=>"HTTP/1.1",
"REQUEST_PATH"=>"/notices"
}
```

According to http://rack.rubyforge.org/doc/files/SPEC.html, "the environment must not contain the keys `HTTP_CONTENT_TYPE` or `HTTP_CONTENT_LENGTH` (use the versions without `HTTP_`)". So this could also apply to content-length header, somehow this header was not set in the presented env by webrick running on rack adapter.