[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [Libevent-users] https-client sample problem on libevent 2.1.7



My observations are for 2.1.5-beta (and earlier) and not for 2.1.7-rc

1) Once the connection has been closed, you need to use a new evhttp_connection object. There is no workaround for this which I'm aware of and also holds true even for the case described by Azat where the remote server responds with a "Connection:close"
2) If you're setting a timeout, it is advisable to set it on the evhttp_connection object just before/after evhttp_make_request() and then reset the timeout to a higher value in the response callback. This is the workaround I adopted to achieve persistent https connections.
i.e 
evhttp_connection_set_timeout_tv(connection, short_request_timeout);
evhttp_make_request(connection, request, EVHTTP_REQ_POST, uri);

in response callback
evhttp_connection_set_timeout_tv(connection, keep-alive-duration);

If you don't reset the timeout to a higher value, the connection will be closed when the request timeout expires irrespective of whether the request succeeded or not.  I haven't dug deep into the bufferevent_ssl layer to determine why this is happening yet.

On Fri, Nov 18, 2016 at 11:21 AM, Azat Khuzhin <a3at.mail@xxxxxxxxx> wrote:
On Fri, Nov 18, 2016 at 11:52 AM, 刘涛 <liutao74748@xxxxxxx> wrote:
> Hi,
>
> I got some problem when I try to make a little bit modification on the
> "https-client" sample code on libevent 2.1.7.
> I built all the libraries and samples successfully on WINDOWS, and the
> original https-client sample also works.
>
> But here comes the problem when I add a few lines of code into the sample
> like this. (Find the code in the attachment please.)
>
> Actually, I just want to fire off a new HTTPS request on the same
> evhttp_connection after receiving the prior request callback, so as to reuse
> the evhttp_connection.
> It works very well when I did the same thing with HTTP client function (on
> libevent 2.0.*), but it doesn't work any more when I turn to HTTPS (on
> libevent 2.1.*)
>
> And the problem is the "http_request_done" callback didn't run once the
> connection is closed, until event_base_dispatch return and the process exit.
> I think the  "http_request_done" callback should run for each HTTPS request,
> not matter succeed or failed, even a error callback.
>
> Any problem with my code? Or is that the bug of 2.1.7?

Hi,

You forget to set "Host", and I guess that you webserver hadn't been
configured to work for https without "Host" header, but http is the
default so it works.
Plus you shouldn't send "Connection: close" if you want to send
another request over the same connection.

You can take a look at modified version here:
https://gist.github.com/azat/2ec7504bcbec53dab9b9bc78ff8efcdb

  Azat.
***********************************************************************
To unsubscribe, send an e-mail to majordomo@xxxxxxxxxxxxx with
unsubscribe libevent-users    in the body.



--
Sanjiv Raj


Marvin: I've been talking to the ship's computer.
Arthur: And?
Marvin: It hates me.