[erlang-questions] packet_size option of decode_packet

Benoit Chesneau bchesneau@REDACTED
Thu Jun 6 16:04:56 CEST 2013


ok sorry for the noise. Did a quick manual test and it seems to use
that size for the maximum length of a request line which is good:


    2> Test1.
    <<"GET / HTTP/1.1\r\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"...>>
    3> erlang:decode_packet(http_bin, Test1, [{packet_size, 4092}]).
    {ok,{http_request,'GET',{abs_path,<<"/">>},{1,1}},
        <<"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"...>>}
    4> byte_size(Test1).
    8208
    5> erlang:decode_packet(http_bin, Test1, [{packet_size, 8}]).
    {error,invalid}
    6> erlang:decode_packet(http_bin, Test1, [{packet_size, 16}]).
    {ok,{http_request,'GET',{abs_path,<<"/">>},{1,1}},
        <<"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"...>>}


- benoit


On Thu, Jun 6, 2013 at 3:53 PM, Benoit Chesneau <bchesneau@REDACTED> wrote:
> The doc says :
>
> {packet_size, integer()}
> Sets the max allowed size of the packet body. If the packet header
> indicates that the length of the packet is longer than the max allowed
> length, the packet is considered invalid. Default is 0 which means no
> size limit.
>
>
> But I wonder what does it means for http parsing.
>
> If I do
>
> {ok, Data} = gen_tcp:recv(Socket, 0, infinity),
> decode_packet(http_bin, Data, [{packet_size, 4096}]).
>
>
> What would happen if bytes_size(Data) > 4096 but the request line
> itself only take 1024 bytes ?
>
> - benoit



More information about the erlang-questions mailing list