Re: Need urgent help for HTTPS
Date: Wed, 24 Nov 2010 11:41:30 -0800
On Wed, Nov 24, 2010 at 12:15:40PM -0500, amit paliwal wrote:
> Thanks Dan, so if I follow your words can my sequence of operations be like
> 1) DO HTTP GET by setting options and then doing curl_easy_perform(). This will
> send the initial message to server.
This will not only send the initial message, but receive the response from that
message as well.
> 2) Then fetch the socket descriptor using some option and set the option
> CONNECT_ONLY and do a curl_easy_recv() on that socket handle. (Here I am
> confused, if I say CONNECT_ONLY before any thing starts I will have to send
> HTTP GET by my own and if I dont do then I will not be able to use
> curl_easy_send() and recv() because documentation says curl_easy_send() can be
> used only when we set CONNECT_ONLY option)
After setting CONNECT_ONLY, you'll have to call curl_easy_perform() as well.
> 3) when data will be available, curl_easy_recv() will be called and I will get
> my handle called where I will get HTTP header+my protocol data. If this is
> right then it means, I will have to parse HTTP header by my own and I can not
> use libcurl's callback for parsing HTTP header.
curl_easy_recv() isn't a callback. It's analagous to recv(2) and your code must
call it every time it wants to receive a block of data from the socket.
> 4) When I want to send response, prepare payload and call curl_easy_send(). In
> this step, I will have to prepare HTTP GET header by my own and on top of that
> my protocol data and then send to server.
If your custom protocol interleaves valid HTTP sessions among proprietary event
passing stages, then you *might* be forced to do subsequent HTTP sessions
manually. It depends on if an easy handle with a persistent connection
can be switched out of CONNECT_ONLY mode. Conceptually, I think you should be
> If I do operations by using curl_easy_send() and curl_easy_recv() functions
> then I am not using much of libcurl's functionality right?
If you have to do HTTP sessions manually, then no, you won't be.
This is what I suggest trying:
1) Set up a normal, persistent HTTPS GET transfer then call
curl_easy_perform() to run it to send the request & get the response. Because
you set up the connection to be persistent, the socket will be left open.
2) Set CONNECT_ONLY on the same easy handle and call curl_easy_perform() once
again. This second curl_easy_perform() ought to do nothing (since the previous
connection was persistent and was already established).
3) Call curl_easy_send()/recv() as needed for proprietary phase.
4) Set CONNECT_ONLY to 0 and set any other options for a second HTTP transfer,
then call curl_easy_perform(). Hopefully, this will reuse the existing socket
and do another normal HTTP transfer.
5) Go back to step 2 if needed.
I don't think this type of scenario has been tested before, but I think
it should work.
List admin: http://cool.haxx.se/list/listinfo/curl-library
Received on 2010-11-24