393 Commits

Author SHA1 Message Date
Azat Khuzhin
b0d3964ff5 http: fix evhttp_request_own() by checking EVHTTP_USER_OWNED in more cases
Suggested-by: @ellzey
Fixes: http/request_own
Fixes: #68
2015-09-09 19:31:12 +03:00
Azat Khuzhin
7ed02ac129 http: fix detecting EOF without write
Before this patch http server don't knows when client disconnected until it
will try to write to it, IOW to detect is client still alive you need to write
something to client socket, however it is not convenient since it requires to
store all clients somewhere and poll them periodically, and I don't see any
regressions if we will leave EV_READ always (like libevhtp do), since we
already reset read callback in evhttp_write_buffer() (see
http/write_during_read).

Also since we don't disable EV_READ anymore we don't need some enable EV_READ,
so we will reduce number of epoll_ctl() calls.

Covered-by: http/terminate_chunked_oneshot
Covered-by: http/write_during_read
Fixes: #78
2015-09-09 18:06:42 +03:00
Azat Khuzhin
dfad1a460a http: eliminate warning about "socklen" in evhttp_connection_connect_() 2015-08-19 23:00:49 +03:00
Azat Khuzhin
a50f5f0ac0 http: reuse connected address only with EVHTTP_CON_REUSE_CONNECTED_ADDR 2015-08-18 20:06:53 +03:00
Azat Khuzhin
54c887d823 http: use IP address that we got before (if any) during retrying
Before this patch every time we are retrying our request we resolve
domain, but we could optimize this (since UDP is slow) by using cached
conn_address value, so do this.
2015-08-18 20:06:52 +03:00
Azat Khuzhin
8bb3842552 bufferevent: move conn_address out from http into bufferevent
In http the only case when when we could store it is when we already
connected, *but* if we are doing request using domain name, then we need
to do request to nameserver to get IP address, and this is handled by
bufferevent.
So when we have IP address (from nameserver) and don't have connection
to this IP address, we could already cache it to avoid extra DNS
requests (since UDP is slow), and we can't do this from http layer, only
from bufferevent.
2015-08-18 20:06:52 +03:00
Azat Khuzhin
22061ac1e9 http: introduce evhttp_request_free_() helper 2015-08-18 11:58:13 +03:00
Azat Khuzhin
6540da3893 http: introduce evhttp_is_request_connection_close() helper 2015-08-18 11:57:54 +03:00
Mark Ellzey
bdeec440f1 Merge pull request #190 from JohnOhl/evhttp-post-fix
evhttp: Fix failure to send all output data for POST/PUT requests
2015-06-17 08:24:52 -07:00
Nick Mathewson
7fd4941465 Merge remote-tracking branch 'origin/pr/182' 2014-11-30 19:26:20 -05:00
John Ohl
24eea0da97 evhttp: Fix failure to send all output data for POST/PUT requests 2014-11-24 02:32:23 -05:00
John Ohl
10fe4ef300 Prevent duplicate event_del on fd 2014-11-16 23:40:16 -05:00
John Ohl
2b9ec4c13c Implement interface that provides the ability to have an outbound evhttp_connection free itself once all requests have completed 2014-10-26 01:25:28 -04:00
Azat Khuzhin
bc79cc5c80 http: reset connection before installing retry timer (fix http retries handling)
This will fix some invalid read/write:
==556== Invalid read of size 8
==556==    at 0x4E4EEC6: event_queue_remove_timeout (minheap-internal.h:178)
==556==    by 0x4E508AA: event_del_nolock_ (event.c:2764)
==556==    by 0x4E53535: event_base_loop (event.c:3088)
==556==    by 0x406FCFA: dispatch (libcrawl.c:271)
==556==    by 0x402863: main (crawler.c:49)
==556==  Address 0x68a3f18 is 152 bytes inside a block of size 400 free'd
==556==    at 0x4C29C97: free (in /usr/local/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==556==    by 0x406F140: renew (libcrawl.c:625)
==556==    by 0x4E6CDE9: evhttp_connection_cb_cleanup (http.c:1331)
==556==    by 0x4E6E2B2: evhttp_connection_cb (http.c:1424)
==556==    by 0x4E4DF2D: bufferevent_writecb (bufferevent_sock.c:310)
==556==    by 0x4E52D1D: event_process_active_single_queue (event.c:1584)
==556==    by 0x4E53676: event_base_loop (event.c:1676)
==556==    by 0x406FCFA: dispatch (libcrawl.c:271)
==556==    by 0x402863: main (crawler.c:49)
But this one because of some invalid write before (I guess).

It is 100% reproduced during massive crawling (because this process
has many different servers), but after spending some time for trying to
reproduce this using some simple tests/utils I gave up for a few days (I
have a lot of work to do), but I'm sending this patch as a reminder.

Just in case, I've tried next tests:
- mixing timeouts/retries
- shutdown http server and return it back
- slow dns server for first request
- sleep before accept
- hacking libevent sources to change the behaviour of http layer (so it
  will go into that function which I'm insterested in).
2014-09-30 18:48:15 +04:00
Nick Mathewson
73615a3723 Merge pull request #118 from azat/http-forward-family-to-bufferevent
Add evhttp_connection_set_family() to set addrinfo->family for DNS requests
2014-09-18 11:31:52 -04:00
Azat Khuzhin
12c29b0f6e Add evhttp_connection_set_family() to set addrinfo->family for DNS requests
This is useful if you want to avoid extra dns requests.
2014-03-21 17:32:09 +04:00
Nick Mathewson
e660db6d5f Catch over-large port numbers early in http
Otherwise integer overflow potentially turns the port number into garbage.
2014-03-18 11:39:23 -04:00
Andrew Sweeney
da86dda951 evhttp_request_set_on_complete_cb to be more specific about what the function actually does and usage 2014-01-06 20:36:31 -05:00
Andrew Sweeney
b083ca0551 Provide on request complete callback facility
This patch provides the ability to receive a callback on the completion of a
request.  The callback takes place immediately before the request's resources
are released.
2014-01-05 20:35:46 -05:00
Balint Reczey
b0bd7fe1db Allow registering callback for parsing HTTP headers
Slightly changed version of Espen Jürgensen's
commit 548141e72312126fa6121f6a5f436đ251c7fb1251 for forked-daapd.
2013-11-18 18:24:15 +01:00
Julien BLACHE
8d8decf114 Add a variant of evhttp_send_reply_chunk() with a callback on evhttp_write_buffer()
evhttp_write_buffer() used by evhttp_send_reply_chunk() can take callback
executed when (part of) the buffer has been written. Using this callback to
schedule the next chunk avoids buffering large amounts of data in memory.
2013-11-18 15:39:47 +01:00
Azat Khuzhin
0c7f0405e3 http: implement new evhttp_connection_get_addr() api.
Basically tcp final handshake looks like this:
    (C - client, S - server)
    ACK[C] - FIN/ACK[S] - FIN/ACK[S] - ACK [C]

However there are servers, that didn't close connection like this,
while it is still _considered_ as valid, and using libevent http layer
we can do requests to such servers.

Modified handshake:
    (C - client, S - server)
    ACK[C] - RST/ACK[S] - RST/ACK[S]

And in this case we can't extract IP address from socket, because it is
already closed, and getpeername() will return: "transport endpoint is not connected".
So we need to store address that we are connecting to, after we know it,
and that is what this patch do.

I have reproduced it, however it have some extra packages.
(I will try to fix it)
https://github.com/azat/nfq-examples/blob/master/nfqnl_rst_fin.c
2013-10-14 11:22:29 -04:00
Nick Mathewson
4464bd2396 Tweak indentation 2013-10-10 16:10:50 -04:00
Nicolas Martyanoff
5a5acd9a70 add a http default content type option 2013-09-30 18:11:26 +02:00
Nick Mathewson
b04d13cd72 Merge remote-tracking branch 'origin/patches-2.0' 2013-09-09 12:06:53 -04:00
Nate Rosenblum
5eb178855a Avoid racy bufferevent activation
The evhttp_send_reply method invokes evhttp_write_buffer with a
callback that may release the underlying request object and
bufferevent upon completion. This cleanup callback is invoked by the
underlying bufferevent's write callback. Improperly enabling write
events before referencing the bufferevent could lead to use after free
and memory corruption.
2013-09-09 11:59:00 -04:00
Nick Mathewson
f22049e359 Fix an unlikely but possible error case for http connections
Found by coverity
2013-08-06 19:17:08 -04:00
Maxime Henrion
a7f82a314f Add evhttp_connection_get_server(). 2013-07-31 21:55:13 -04:00
Maxime Henrion
31db8a02bd Fix a double close() bug in evhttp when the underlying bufferevent uses BEV_OPT_CLOSE_ON_FREE. 2013-05-24 11:04:11 -04:00
Azat Khuzhin
7b077194cc Add new error_cb for actual reporting of HTTP request errors.
It is useful to know why you callback called with NULL (i.e. it failed),
for example if you set max_body with evhttp_connection_set_max_body_size()
you must know that it failed because of body was longer than this size.

 (Commit message tweaked by Nick)
2013-04-25 15:11:44 -04:00
Azat Khuzhin
de8101a884 Move prototype of evhttp_decode_uri_internal() to http-internal.h
Make it non static, that can be called from tests
2013-03-01 12:00:24 +04:00
Azat Khuzhin
e1903e3ace uri decode: changed the test for the existence of the next character
Fix for 64b6eceaba1a4

More info here
64b6eceaba (commitcomment-2714685)
2013-02-28 23:10:02 +04:00
Azat Khuzhin
64b6eceaba uri decode: fix for warning "use of uninitialised value"
This patch add check in evhttp_decode_uri_internal() that next 2 symbols
are exists in array of chars for decoding, if don't have two next 2
symbols don't try to decode '%FF'
2013-02-28 17:19:44 +04:00
Nick Mathewson
9709461457 Merge remote-tracking branch 'origin/patches-2.0' 2013-02-14 14:13:11 -05:00
Greg Hazel
b618204216 fix #73 and fix http_connection_fail_test to catch it 2013-02-14 09:54:56 -08:00
Nick Mathewson
2ecd894725 Merge pull request #39 from azat/fix-http-for-ipv6
Fix ipv6 support for http. When URL contain domain, not IP address.
2013-02-04 13:49:08 -08:00
Azat Khuzhin
71e709c782 Fix ipv6 support for http. When URL contain domain, not IP address.
Before this patch socket created before domain was resolved, and it
always create with AF_INET (ipv4), but we must create socket only after
domain was resolved to understad which protocol family have domain
address.

Thank to Patrick Pelletier, who found this bug.
2013-01-23 02:45:32 +04:00
Patrick Pelletier
80e220eef7 fix some hinky indentation in evhttp_make_request 2013-01-18 20:25:41 -08:00
Sebastian Hahn
b452a43450 Fix harmless clang enum warning 2012-12-31 18:29:56 +01:00
Nick Mathewson
7afbd60266 Use EVUTIL_SOCKET_ERROR() wrapper to save/restor errno in evhttp_connection_fail_ 2012-11-16 11:51:42 -05:00
Nick Mathewson
29fea33a7c Merge remote-tracking branch 'ppelleti/preserve-errno' 2012-11-16 11:49:46 -05:00
Jay R. Wren
4f4d0c9318 add evhttp_request_get_response_code_line
This is needed to be able to read the response code line especially
when acting as an http client using evhttp_make_request.

(patched by nickm to make the return value const)
2012-11-16 11:48:03 -05:00
Nick Mathewson
61b93af561 Move evutil_rtrim_lws_ to evutil.c where it belongs 2012-11-16 11:41:59 -05:00
Nick Mathewson
c6ff381270 Remove internal ws from multiline http headers correctly
According to RFC2616:

   All linear white space, including folding, has the same semantics
   as SP. A recipient MAY replace any linear white space with a single
   SP before interpreting the field value or forwarding the message
   downstream.
2012-11-16 11:38:53 -05:00
Nick Mathewson
ac42519769 Remove trailing tabs in HTTP headers as well. 2012-11-16 11:29:34 -05:00
Nick Mathewson
aa59d805f5 Clean up rtrim implementation
If I understand the C standard correctly, you can't actually point
at a position immediately _before_ the start of an object; only at the
position immediately after.

According to J.2 in the standard, in its big list of undefined behavior:

 "The behavior is undefined in the following circumstances:
     ...
   — Addition or subtraction of a pointer into, or just beyond, an
    array object and an integer type produces a result that does not
    point into, or just beyond, the same array object (6.5.6)."

So we've got to fix rtrim to not do that.  Also, make it unit tested,
and give it an evutil_*_ name.
2012-11-16 11:13:29 -05:00
Artem Germanov
370a2c0213 ignore LWS after field-content in headers 2012-11-16 10:59:43 -05:00
Patrick Pelletier
36d0ee5c9f preserve errno in evhttp_connection_fail_ for inspection by the callback 2012-11-13 21:22:39 -08:00
Nick Mathewson
f9182d7249 Merge remote-tracking branch 'github/20_win64_compilation' into 21_win64_compilation
Conflicts:
	http.c
	signal.c
2012-11-02 11:46:14 -04:00
Nick Mathewson
62bd2c44f1 Fix compilation on mingw64 with -DUSE_DEBUG 2012-11-02 11:44:29 -04:00