ninenines / cowboy

Small, fast, modern HTTP server for Erlang/OTP.
https://ninenines.eu
ISC License
7.29k stars 1.17k forks source link

Playing with cowboy_client #510

Closed cjimison closed 11 years ago

cjimison commented 11 years ago

Hi all,

This is not a bug but just a request for some clarity. I understand that the cowboy_client is still in "prototype" mode but I wanted to kick the tires and play around with it some. As per an earlier post, I understand that because this code is not officially released the onus is on me to learn how it works, but any help would be greatly appreciated.

I would like to do a simple get request to www.google.com.

    {ok, C1} = cowboy_client:init([]),
    {ok, C2} = cowboy_client:request(<<"GET">>, <<"http://www.google.com">>, C1),
    {ok, _Status, Header, C3} = cowboy_client:response(C2),
    io:format("Header = ~p~n", [Header]),
    {ok, Data, _C4} = cowboy_client:response_body(C3), %<-- fails
    io:format("Data = ~s~n", [binary_to_list(Data)]).

google is returning the results as a {<<"transfer-encoding">>,<<"chunked">>} so there is no body or content-length to speak of and I get why this will fail. However I am not sure what to do from here. I can see part of the results I am looking for in the C3#client.buffer field but I am not sure what API I should use to pull that data out.

Once again any help would be awesome, but I understand if this is super low priority.

Thanks!

dvv commented 11 years ago

You might want to take off from https://github.com/dvv/social/blob/master/src/cowboy_request.erl

essen commented 11 years ago

cowboy_client doesn't have chunked support yet.

cjimison commented 11 years ago

cowboy_client doesn't have chunked support yet.

That is what I expected, but I was hoping I just missed something :)

You might want to take off from https://github.com/dvv/social/blob/master/src/cowboy_request.erl

Thanks for the suggestion! My only concern with this code is it bypasses the lack of chunked transfer-encoding by forcing the client protocol to http 1.0. Not a bad idea assuming that app does not require http 1.1.

One last question: Is there a roadmap or time table for cowboy_client? I really like where you are going with this as an alternative to inets:httpc or ibrowse.

Thanks again!

dvv commented 11 years ago

I would assume that reading response body is the same to reading request body from cowboy_req. May be even no radical changes would be required )

essen commented 11 years ago

No roadmap for it yet, sorry.

cjimison commented 11 years ago

Not a problem. Thanks for all the info!