|
View:
New views
3 Messages
—
Rating Filter:
Alert me
|
|
|
Potential bug in {packet, http}HI,
When I used erlang:decode_packet to parse a HTTP request with an absolute URI I get the expected outcome : 1> erlang:decode_packet(http, <<"GET http://www.foo.com/bar HTTP/1.0\r\n">>, []). {ok,{http_request,'GET', {absoluteURI,http,"www.foo.com",undefined,"/bar"}, {1,0}}, <<>>} However, when I use {packet, http} for the same thing the outcome is not what I expect : 1> my_httpd:start(). Listening on port: 8082 ok 2> my_httpd:do_client(<<"GET http://www.foo.com/bar HTTP/1.0\r\n">>). Connecting to localhost:8082 ... Connected ok Method: 'GET', Uri: {absoluteURI,http,"www.foo.com",undefined,"/bar HTTP/1"}, Version: {1, 0} The code of my_httpd is below. Is this a bug or am I missing something? Thanks, Colm -module(my_httpd). -export([ start/0, do_client/0, do_client/1 ]). -define(LPORT, 8082). -define(LOPTS, [binary, {packet, 0}, {active, false}, {packet, http}] ). start() -> spawn(fun init_server/0), ok. do_client() -> do_client(<<"GET http://www.foo.com/bar HTTP/1.0\r\n">>). do_client(Bin) -> io:format("Connecting to localhost:~p ...~n", [?LPORT]), {ok, CSock} = gen_tcp:connect("localhost", ?LPORT, [binary]), io:format("Connected~n"), ok = gen_tcp:send(CSock, Bin), gen_tcp:close(CSock), ok. init_server() -> io:format("Listening on port: ~p~n", [?LPORT]), {ok, LSock} = gen_tcp:listen(?LPORT, ?LOPTS), server_loop(LSock). server_loop(LSock) -> {ok, Sock} = gen_tcp:accept(LSock), catch(handle_client(Sock)), catch(gen_tcp:close(Sock)), server_loop(LSock). handle_client(Sock) -> case gen_tcp:recv(Sock, 0) of {ok, {http_request, Method, Uri, Version}} -> io:format("Method: ~p, Uri: ~p, Version: ~p~n", [Method, Uri, Version]); {ok, Other} -> io:format("Unexpected: ~p~n", [Other]); {error, closed} -> io:format("Closed~n") end. ________________________________________________________________ erlang-bugs mailing list. See http://www.erlang.org/faq.html erlang-bugs (at) erlang.org |
|
|
Re: Potential bug in {packet, http}On Sat, Sep 19, 2009 at 4:51 PM, Colm Dougan <colm.dougan@...> wrote:
> HI, > > When I used erlang:decode_packet to parse a HTTP request with an > absolute URI I get the expected outcome : > > 1> erlang:decode_packet(http, <<"GET http://www.foo.com/bar > HTTP/1.0\r\n">>, []). > {ok,{http_request,'GET', > {absoluteURI,http,"www.foo.com",undefined,"/bar"}, > {1,0}}, > <<>>} > > However, when I use {packet, http} for the same thing the outcome is > not what I expect : > > 1> my_httpd:start(). > Listening on port: 8082 > ok > 2> my_httpd:do_client(<<"GET http://www.foo.com/bar HTTP/1.0\r\n">>). > Connecting to localhost:8082 ... > Connected > ok > Method: 'GET', Uri: {absoluteURI,http,"www.foo.com",undefined,"/bar > HTTP/1"}, Version: {1, 0} > > The code of my_httpd is below. Is this a bug or am I missing something? > What version of Erlang are you using? I tried your code on R13B01 and it was just fine, but I see the same error you got when I use R12B-5. --steve |
|
|
Re: Potential bug in {packet, http}On Sat, Sep 19, 2009 at 10:13 PM, Steve Vinoski <vinoski@...> wrote:
> > > On Sat, Sep 19, 2009 at 4:51 PM, Colm Dougan <colm.dougan@...> wrote: >> >> HI, >> >> When I used erlang:decode_packet to parse a HTTP request with an >> absolute URI I get the expected outcome : >> >> 1> erlang:decode_packet(http, <<"GET http://www.foo.com/bar >> HTTP/1.0\r\n">>, []). >> {ok,{http_request,'GET', >> {absoluteURI,http,"www.foo.com",undefined,"/bar"}, >> {1,0}}, >> <<>>} >> >> However, when I use {packet, http} for the same thing the outcome is >> not what I expect : >> >> 1> my_httpd:start(). >> Listening on port: 8082 >> ok >> 2> my_httpd:do_client(<<"GET http://www.foo.com/bar HTTP/1.0\r\n">>). >> Connecting to localhost:8082 ... >> Connected >> ok >> Method: 'GET', Uri: {absoluteURI,http,"www.foo.com",undefined,"/bar >> HTTP/1"}, Version: {1, 0} >> >> The code of my_httpd is below. Is this a bug or am I missing something? > > What version of Erlang are you using? I tried your code on R13B01 and it was > just fine, but I see the same error you got when I use R12B-5. Yeah I'm using 12B-5. Before I posted I checked the 13B01 changes file for anything that sounded like this but my search came up empty However, now I've checked the 13A changes file I see this : OTP-7682 A bug fixed for TCP sockets with option {packet,http}. An HTTP request with an absolute URI was returned with a corrupt path string. This bug did only exist in R12B-4 and R12B-5. My bad (although IMO it would be nice if bugs fixed in a beta release are mentioned in the next official release changes file). Colm ________________________________________________________________ erlang-bugs mailing list. See http://www.erlang.org/faq.html erlang-bugs (at) erlang.org |
| Free embeddable forum powered by Nabble | Forum Help |