extend/cowboy — Issue #103: Rest And Media-Type Wiredness
Author: Licenser
Created: 2011-12-11 04:28:14+00:00
State: open

I encountered the refusal from the Rest handler to work with media types that specify a charset.

The application asks for:

```Erlang
{'Content-Type',<<"application/json; charset=UTF-8">>}
%...
{'Accept',<<"application/json">>}
```
The Handler Provides:

```Erlang
%...
{{<<"application">>, <<"json">>, []}, to_json},
{{<<"application">>, <<"json">>, [{<<"charset">>,<<"UTF-8">>}]}, to_json}
%...
{{<<"application">>, <<"json">>, []}, from_json},
{{<<"application">>, <<"json">>, [{<<"charset">>,<<"UTF-8">>}]}, from_json}
%...
```

Now this should match but keeps returning a 406 not applicable.

The Request when checking for provided is:

```Erlang
{http_req,#Port<0.13552>,cowboy_tcp_transport,keepalive,'POST',
{1,1},
undefined,
[<<"localhost">>],
undefined,<<"localhost">>,8080,
[<<"api">>,<<"v1">>,<<"shiptype">>],
undefined,<<"/api/v1/shiptype">>,undefined,<<>>,[],
[{'Cache-Control',<<"no-cache">>},
{'Pragma',<<"no-cache">>},
{'Content-Length',<<"52">>},
{'Content-Type',<<"application/json; charset=UTF-8">>},
{'Connection',<<"keep-alive">>},
{<<"Dnt">>,<<"1">>},
{'Accept-Charset',<<"ISO-8859-1,utf-8;q=0.7,*;q=0.7">>},
{'Accept-Encoding',<<"gzip, deflate">>},
{'Accept',<<"application/json">>},
{'User-Agent',<<"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:6.0.2) Gecko/20100101 Firefox/6.0.2">>},
{'Host',<<"localhost">>}],
[{'Connection',[<<"keep-alive">>]}],
undefined,waiting,
<<"{\"id\":42,\"user_id\":1,\"name\":\"Cool\",\"script_id\":null}">>,
waiting,[],<<>>,
{#Fun,crash}}
```

And when checking for accepted:

```Erlang
{http_req,#Port<0.13552>,cowboy_tcp_transport,keepalive,'POST',
{1,1},
undefined,
[<<"localhost">>],
undefined,<<"localhost">>,8080,
[<<"api">>,<<"v1">>,<<"shiptype">>],
undefined,<<"/api/v1/shiptype">>,undefined,<<>>,[],
[{'Cache-Control',<<"no-cache">>},
{'Pragma',<<"no-cache">>},
{'Content-Length',<<"52">>},
{'Content-Type',<<"application/json; charset=UTF-8">>},
{'Connection',<<"keep-alive">>},
{<<"Dnt">>,<<"1">>},
{'Accept-Charset',<<"ISO-8859-1,utf-8;q=0.7,*;q=0.7">>},
{'Accept-Encoding',<<"gzip, deflate">>},
{'Accept',<<"application/json">>},
{'User-Agent',<<"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:6.0.2) Gecko/20100101 Firefox/6.0.2">>},
{'Host',<<"localhost">>}],
[{'If-Modified-Since',undefined},
{'If-None-Match',undefined},
{'If-Unmodified-Since',undefined},
{'If-Match',undefined},
{'Accept',[{{<<"application">>,<<"json">>,[]},1000,[]}]},
{'Connection',[<<"keep-alive">>]}],
undefined,waiting,
<<"{\"id\":42,\"user_id\":1,\"name\":\"Cool\",\"script_id\":null}">>,
waiting,
[{<<"Location">>,<<"/api/v1/shiptype/55">>},
{<<"Variances">>,<<"Accept">>},
{<<"Content-Type">>,[<<"application">>,<<"/">>,<<"json">>,<<>>]}],
<<>>,
{#Fun,crash}}
```