weird http parsing

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

weird http parsing

Andy W. Song
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. 

I know http header field name is case insensitive but Erlang should not silently and inconsistently modify it. 

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.

Any ideas to mitigate this?

Thanks
Andy

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: weird http parsing

Sverker Eriksson
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

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions