https: free struct https if openssl initialization fails
https: make sure err has a sane value leaving read_chunk_size()
https: move code around to arrange for keepalive

* Move request_ctx setup right after the allocation so it's not so
easy to mistakenly set up fields cleared later by the memset()

* Move request_done() above the read callback, so we can call it
from there.

* Move set_read_state() above drain_body() so we can call it there
once we know we can move to DONE.
https: detect end of request in the read callback

Introduce a new read state, READ_DONE, for situations where we
detect we've read the whole response.

  a) For "Transfer-Encoding: chunked" this is indicated by a
     0-length chunk

  b) For "normal" responses we check if Content-Length is set
     and we've consumed Content-Length bytes.

This prepares us for the situation where "we're done" might not
be indicated by the remote end (or us) closing the connection ;)

Also while we're in READ_BODY, loop until we've exhausted the input
buffer. We don't have level-triggering so we'd better deal with all
the data before returning from the read callback. We may have
problems with this still but at least we're not hitting them.
https: move connection management behind struct conn_stash

This will hide the fact that we'll start reusing SSL connections.

For now it's just restructuring the code and moving the management
bits behind conn_stash_get_bev()/conn_stash_put_bev()
https: split request submitting to a separate helper

We won't be able to do it from the BEV_EVENT_CONNECTED callback
anymore once we start reusing connections.
https: move submit_request() from the event callback

When we do keepalive we won't get BEV_EVENT_CONNECTED. So
we'll just submit requests before we pass control to libevent.
https: do keepalive connections

Make conn_stash actually store connections and return stashed
connections instead of fresh ones, adjust "Connection:" header
accordingly.

We can't really handle stashed connections that have been closed, but
that's a separate matter o:)
https: remove the cb_event dirty shutdown special-casing

This no longer appears after

     52da785 https: detect end of request in the read callback

after which we correctly handle all input before throwing the
connection away. "Oopf".
https: add a new READ_NONE state, (cb_read() never called)

To have a sane heuristic for when we should restart the request
we'll be using this.

We can't use any write counters, as it seems we manage to write()
the request even when it's a closed connection, we'll just get an
error soon after.

This is definitely something that wants refining later.
https: copy request body instead of losing it

In order to do request restarts transparently without burdening
https_request() callers we cannot lost the request body.

We used to use evbuffer_add_buffer() for copying the request body
into output. Doing this drains the original buffer, which is not
acceptable.

So store request body in struct request_ctx as a proper data blob
and do evbuffer_add_reference() on it when we construct the output
buffer. We don't need to specify cleanup functions as we only get
rid of the struct request_ctx when we know nothing's touching the
bufferevent.
keepalive: reconnect keepalive connections that have been closed

The heuristics for "are we disconnected" probably aren't perfect,
but reconnecting a timed out connection and replacing the stashed
connection with the new fresh one looks to be working.

All of this takes place behind the https_request() curtains, so the
caller will never know what goes on.

I suppose we'll need a limit for retries anyway, just to be sure.
Implement the no-keepalive debugging option

Passing -n will cause https keepalive to be disabled. We do this
by passing Connection: close on requests and just discarding
connections at conn_stash_put_bev() instead of stashing them away.

This has the obvious effect of conn_stash_get_bev() never finding a
stashed connection and always returning a fresh one.

And lo and behold, there's a nasty wart in https.c:cb_event() again
to deal with end-of-response :(

Also a fair amount of noise in the diff as we pass the argument all
the way down from main via https to conn_stash.
Merge branch 'http-keepalive'

Keep-alive bits for https requests. This is now the default, but you
can pass -n to get 'Connection: close' behaviour.