[99s-extend] Body length and content-length mismatch

Loïc Hoguin essen at ninenines.eu
Fri Feb 27 18:11:42 CET 2015


It looks like the client is telling you BS.

On 02/27/2015 06:07 PM, Samir Sow wrote:
> Hi,
>
> I’m facing an issue with the cowboy_req:body call.
>
> The header show a length of 2 while the body itself is a binary string which has a size greater than 2 for sure.
> Trying to use cowboy_req:body with the length option does not make any difference.
>
> How can i retrieve the data ?
> Any clue ?
>
> Thank you
>
> {ok,{<<"basic">>,{<<«xxxxx at xxxxxx">>,<<«xxxxxxx">>}},
>            {http_req,
>                {sslsocket,
>                    {gen_tcp,#Port<0.13250>,tls_connection,<0.298.0>},
>                    <0.407.0>},
>                ranch_ssl,keepalive,<0.408.0>,<<"POST">>,'HTTP/1.1',
>                {{xxxxxxxxx},16220},
>                <<«xxxx">>,undefined,xxxx,<<«xxxxx">>,undefined,
>                <<>>,undefined,
>                [{res_1,<<«xxxx">>}],
>                [{<<"content-type">>,<<"application/json">>},
>                 {<<"content-length">>,<<"2">>},
>                 {<<"te">>,<<>>},
>                 {<<"host">>,<<«xxxxx">>},
>                 {<<"authorization">>,
>                  <<"Basic xxxxxxxxxxxxxx">>},
>                 {<<"connection">>,<<"keep-alive">>}],
>                [{<<"authorization">>,
>                  {<<"basic">>,{<<«xxxxxx">>,<<«xxxxxx">>}}},
>                 {<<"connection">>,[<<"keep-alive">>]}],
>                undefined,[],waiting,
>                <<"{\"login\":\»xxxx at xxxxxx\",\»xxxx\":\»xxxx\"}{\"login\":\»xxxx at xxxx\",\»xxxx\":\»xxxxx\"}">>,

And looking at this (the buffer of already received data, presumably 
your whole body, it looks like you receive 2 things. Perhaps the client 
gives you the count of things instead of the length?

Either way if the client provides a wrong content-type you should reject 
the connection.

>                undefined,false,waiting,
>                [{<<"Access-Control-Allow-Credentials">>,<<"true">>},
>                 {<<"Access-Control-Allow-Origin">>,
>                  <<"http://xxxxxxxxx">>}],
>                <<>>,undefined}}
> Samir
>
>
> _______________________________________________
> Extend mailing list
> Extend at lists.ninenines.eu
> https://lists.ninenines.eu/listinfo/extend
>

-- 
Loïc Hoguin
http://ninenines.eu


More information about the Extend mailing list