[erlang-questions] Parsing custom HTTP headers with inet, [{active, false},{packet, http_bin}, ...]

Tony Rogvall <>
Sat Aug 28 12:32:38 CEST 2010


What  version of OTP are you using?

Try:

> erlang:decode_packet(httph, <<"X-WEBARCH-RESOURCE-UUID: 123456789\r\n\r\n">>, []).

Return value should be:

{ok,{http_header,0,"X-WEBARCH-RESOURCE-UUID",undefined,
                 "123456789"},
    <<"\r\n">>}

If this works,  then the problem is probably somewhere else.

tcp-dump?

/Tony


On 28 aug 2010, at 12.11, zabrane Mikael wrote:

> Hi,
> 
> I'm facing a strange problem to parse custom HTTP headers in my server
> code which looks like:
> 
> {ok, ListenSocket} = gen_tcp:listen(9876, [binary, inet, {active,
> false},  {packet, http_bin}, {reuseaddr, true}]),
> ...
> headers(Socket) ->
>    ok = inet:setopts(Socket, [{active, once}]),
>    receive
>         ...
>        {http, _, {http_header, _, Header, _, Val}} ->
>            io:format("---> The header is: ~p: ~p~n", [Header, Val]),
> 
> Trying to send the following custom header "X-ARCHWEB-RESOURCE-UUID"
> works fine, and the custom header appears
> correctly in my server code:
> $ curl -x localhost:9876 -H 'X-ARCHWEB-RESOURCE-UUID: 123456789' --url
> http://www.foo.com
> 
> 1> ...
> ---> The header is: <<"X-ARCHWEB-RESOURCE-UUID">>: <<"123456789">>
> 
> But changing a bit the custom header name to "X-WEBARCH-RESOURCE-UUID"
> doesn't work
> and the server don't even print it out (i.e nothing is received).
> 
> Now, trying with "X-WEBARCH-RESOURC-UUID" (notice the missing "E" at
> the end of "RESOURC") works fine:
> 
> 2> ...
> ---> The header is: <<"X-WEBARCH-RESOURC-UUID">>: <<"123456789">>
> 
> Even bad, trying with "X-WEBARCH-RESOURCE" completely alter the
> letters cases (first letter is capital letter and the rest is
> lowercase):
> 
> 3>
> ---> The header is: <<"X-Webarch-Resource">>: <<"123456789">>
> 
> Could someone tell me what am I doing wrong?
> Is there any option to tell "inet" to not alter the headers at all?
> 
> -- 
> Regards
> Zabrane
> 
> ________________________________________________________________
> erlang-questions (at) erlang.org mailing list.
> See http://www.erlang.org/faq.html
> To unsubscribe; mailto:
> 



More information about the erlang-questions mailing list