новости сообщество форум вики
Erlang по-русски. Форум » Erlang »

socketopts - {packet, http} - body приходит в http_error

(2 posts)

  1. -module(wget).
    -compile(export_all).
    
    main() ->
    
        {ok, Socket} = gen_tcp:connect(\\\"google.com\\\", 80, [{packet, http}]),
        ok = gen_tcp:send(Socket, \\\"GET / HTTP/1.0\r\n\r\n\\\"),
    
        receive_data(Socket),
        io:format(\\\"Stream ends.~n\\\").
    
    receive_data(Socket) ->
        receive
            {tcp_closed, Socket} ->
                io:format(\\\"Socket closed~n\\\", []);
            {http, Socket, {http_response, Version, Code, Message}} ->
                io:format(\\\"Http response found: Version: ~p, Code: ~p, Message: ~p. Socket: ~p~n\\\", [Version, Code, Message, Socket]),
                receive_data(Socket);
            {http, Socket, {http_header, Len, Field, _WTF, Value}} ->
                io:format(\\\"Header ~p = ~p (~p bytes) received. WTF?: ~p~n\\\", [Field, Value, Len, _WTF]),
                receive_data(Socket);
            {http, Socket, http_eoh} ->
                io:format(\\\"EOH marker received~n\\\", []),
                inet:setopts(Socket, [{packet, 0}]),
                receive_data(Socket);
            {http, Socket, {http_error, Message}} ->
                io:format(\\\"Http error: ~p~n\\\", [Message]),
                receive_data(Socket);
            _Any ->
                io:format(\\\"Received unknown message: ~p~n\\\", [_Any])
    
        end.
    

    Запускаю, получаю вывод:

    Http response found: Version: {1,0}, Code: 302, Message: \\"Found\\". Socket: #Port<0.361>
    Header 'Location' = \\"http://www.google.co.il/\\" (26 bytes) received. WTF?: undefined
    Header 'Cache-Control' = \\"private\\" (1 bytes) received. WTF?: undefined
    Header 'Content-Type' = \\"text/html; charset=UTF-8\\" (42 bytes) received. WTF?: undefined
    Header 'Set-Cookie' = \\"PREF=ID=8ea6a1ba57d9411d:TM=1281191330:LM=1281191330:S=uj2vVYepMswCFDZL; expires=Mon, 06-Aug-2012 14:28:50 GMT; path=/; domain=.google.com\\" (47 bytes) received. WTF?: undefined
    Header 'Set-Cookie' = \\"NID=37=Hgd6IJX2At52cunmWnLLb-R493QH-pvqE0dxyqbIlnXNZRWbgjy9J3brjN7_rP_mBu4yM0LRwr_M67uAZPsXr3mFnt1SXYpSsFvWInEKZITS3wkICqfzCYs8m531w3; expires=Sun, 06-Feb-2011 14:28:50 GMT; path=/; domain=.google.com; HttpOnly\\" (47 bytes) received. WTF?: undefined
    Header 'Date' = \\"Sat, 07 Aug 2010 14:28:50 GMT\\" (3 bytes) received. WTF?: undefined
    Header 'Server' = \\"gws\\" (30 bytes) received. WTF?: undefined
    Header 'Content-Length' = \\"221\\" (38 bytes) received. WTF?: undefined
    Header \\"X-Xss-Protection\\" = \\"1; mode=block\\" (0 bytes) received. WTF?: undefined
    EOH marker received
    Http error: \\"<HTML><HEAD><meta http-equiv=\\\"content-type\\\" content=\\\"text/html;charset=utf-8\\\">\n\\"
    Http error: \\"<TITLE>302 Moved</TITLE></HEAD><BODY>\n\\"
    Http error: \\"<H1>302 Moved</H1>\n\\"
    Http error: \\"The document has moved\n\\"
    Http error: \\"<A HREF=\\\"http://www.google.co.il/\\\">here</A>.\r\n\\"
    Http error: \\"</BODY></HTML>\r\n\\"
    Socket closed
    Stream ends.
    

    Т.е. после http_eoh парсер все остальное считает о?ибкой. Это нормальное поведение?

    Я пытался наколдовать на сокет setopts(Socket, {packet, 0}), что б остальное приходило без парсинга, но это ничего не изменило.

    Гугль не помог.

    Отправлено 1 год назад #
  2. Блин, побилось форматирование.

    Вот исходник - http://pastebin.com/Ufvnrs0p

    Отправлено 1 год назад #

RSS экспорт этой темы

Отправить сообщение

Вы должны войти в систему, чтобы оставлять сообщения.

 
 

так же

Популярные тэги



Currently online

No Members around.

twitter