[erlang-questions] weird http parsing

Sverker Eriksson sverker@REDACTED
Mon Jul 25 19:22:39 CEST 2011


Andy W. Song wrote:
> Hi,
>
> I'm using inet:setopts(Sock, [{active,true},{packet, http}]) to receive http
> packets. I found that Erlang silently modifies some http header name fields
> from like "Sec-WebSocket-Origin" to "Sec-Websocket-Origin". But another
> fields "Sec-WebSocket-Version" is not modified. It's quite strange.
>
>   
Yes, header names shorter than 21 characters are modified, while longer 
names are not. I agree it's a bit strange.

> I know http header field name is case insensitive but Erlang should not
> silently and inconsistently modify it.
>   
Wouldn't the best behavior be to *consistently* modify the header names 
to a predefined format (uppercase only first and after '-'). Then you 
can do an exact string compare.

> After I found it I tried to use all lower case. But  "erlang:decode_packet"
> decodes some of the fields into atoms and other not-recognized ones to
> string so it's quite inconvenient to use all lower case.
>
>   
Yes, some header names are recognized and presented as atoms. That is 
documented in erlang:decode_packet.

> Any ideas to mitigate this?
>
>   
If you have control over input, use uppercase only as first character 
and directly after '-'.

/Sverker, Erlang/OTP




More information about the erlang-questions mailing list