Mercurial > dovecot > core-2.2
annotate src/lib-http/http-client-connection.c @ 22656:1789bf2a1e01
director: Make sure HOST-RESET-USERS isn't used with max_moving_users=0
The reset command would just hang in that case. doveadm would never have
sent this, so this is just an extra sanity check.
author | Timo Sirainen <timo.sirainen@dovecot.fi> |
---|---|
date | Sun, 05 Nov 2017 23:51:56 +0200 |
parents | 36a38929734d |
children | cb108f786fb4 |
rev | line source |
---|---|
21390
2e2563132d5f
Updated copyright notices to include the year 2017.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21389
diff
changeset
|
1 /* Copyright (c) 2013-2017 Dovecot authors, see the included COPYING file */ |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
2 |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
3 #include "lib.h" |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
4 #include "net.h" |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
5 #include "str.h" |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
6 #include "hash.h" |
16856
b9498573f0d0
lib-http: http-client: Added support for tunneling SSL conntections through proxy.
Stephan Bosch <stephan@rename-it.nl>
parents:
16855
diff
changeset
|
7 #include "llist.h" |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
8 #include "array.h" |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
9 #include "ioloop.h" |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
10 #include "istream.h" |
17191
790afcf05f0d
lib-http: Wrap response payload istream into a istream-timeout.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
11 #include "istream-timeout.h" |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
12 #include "ostream.h" |
16451
a551409911f9
lib-http: Added connect and request timeout settings.
Timo Sirainen <tss@iki.fi>
parents:
16450
diff
changeset
|
13 #include "time-util.h" |
20951
1d037671b39a
lib-http: Add ioloop and lock wait information to timeout messages.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20828
diff
changeset
|
14 #include "file-lock.h" |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
15 #include "iostream-rawlog.h" |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
16 #include "iostream-ssl.h" |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
17 #include "http-response-parser.h" |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
18 |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
19 #include "http-client-private.h" |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
20 |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
21 /* |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
22 * Logging |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
23 */ |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
24 |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
25 static inline void |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
26 http_client_connection_debug(struct http_client_connection *conn, |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
27 const char *format, ...) ATTR_FORMAT(2, 3); |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
28 |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
29 static inline void |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
30 http_client_connection_debug(struct http_client_connection *conn, |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
31 const char *format, ...) |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
32 { |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
33 va_list args; |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
34 |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
35 if (conn->client->set.debug) { |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
36 |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
37 va_start(args, format); |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
38 i_debug("http-client: conn %s: %s", |
21040
9b04af4cbe62
lib-http: client: Improved labeling of debug messages.
Stephan Bosch <stephan@dovecot.fi>
parents:
21030
diff
changeset
|
39 conn->label, t_strdup_vprintf(format, args)); |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
40 va_end(args); |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
41 } |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
42 } |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
43 |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
44 /* |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
45 * Connection |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
46 */ |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
47 |
17970
7d3325713356
lib-http: client: Connection erroneously indicated that it was ready while SSL handshake was not yet completed.
Stephan Bosch <stephan@rename-it.nl>
parents:
17968
diff
changeset
|
48 static void http_client_connection_ready(struct http_client_connection *conn); |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
49 static void http_client_connection_input(struct connection *_conn); |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
50 |
21029
a3a045122aa4
lib-http: client: Created http_client_connection_failure() handler.
Stephan Bosch <stephan@dovecot.fi>
parents:
21028
diff
changeset
|
51 static inline void |
21425
70083e131e22
lib-http: client: Make sure req->conn is only not NULL when that connection holds a reference to that request.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21424
diff
changeset
|
52 http_client_connection_ref_request(struct http_client_connection *conn, |
70083e131e22
lib-http: client: Make sure req->conn is only not NULL when that connection holds a reference to that request.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21424
diff
changeset
|
53 struct http_client_request *req) |
70083e131e22
lib-http: client: Make sure req->conn is only not NULL when that connection holds a reference to that request.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21424
diff
changeset
|
54 { |
70083e131e22
lib-http: client: Make sure req->conn is only not NULL when that connection holds a reference to that request.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21424
diff
changeset
|
55 i_assert(req->conn == NULL); |
70083e131e22
lib-http: client: Make sure req->conn is only not NULL when that connection holds a reference to that request.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21424
diff
changeset
|
56 req->conn = conn; |
70083e131e22
lib-http: client: Make sure req->conn is only not NULL when that connection holds a reference to that request.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21424
diff
changeset
|
57 http_client_request_ref(req); |
70083e131e22
lib-http: client: Make sure req->conn is only not NULL when that connection holds a reference to that request.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21424
diff
changeset
|
58 } |
70083e131e22
lib-http: client: Make sure req->conn is only not NULL when that connection holds a reference to that request.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21424
diff
changeset
|
59 |
70083e131e22
lib-http: client: Make sure req->conn is only not NULL when that connection holds a reference to that request.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21424
diff
changeset
|
60 static inline bool |
70083e131e22
lib-http: client: Make sure req->conn is only not NULL when that connection holds a reference to that request.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21424
diff
changeset
|
61 http_client_connection_unref_request(struct http_client_connection *conn, |
70083e131e22
lib-http: client: Make sure req->conn is only not NULL when that connection holds a reference to that request.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21424
diff
changeset
|
62 struct http_client_request **_req) |
70083e131e22
lib-http: client: Make sure req->conn is only not NULL when that connection holds a reference to that request.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21424
diff
changeset
|
63 { |
70083e131e22
lib-http: client: Make sure req->conn is only not NULL when that connection holds a reference to that request.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21424
diff
changeset
|
64 struct http_client_request *req = *_req; |
70083e131e22
lib-http: client: Make sure req->conn is only not NULL when that connection holds a reference to that request.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21424
diff
changeset
|
65 |
70083e131e22
lib-http: client: Make sure req->conn is only not NULL when that connection holds a reference to that request.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21424
diff
changeset
|
66 i_assert(req->conn == conn); |
70083e131e22
lib-http: client: Make sure req->conn is only not NULL when that connection holds a reference to that request.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21424
diff
changeset
|
67 req->conn = NULL; |
70083e131e22
lib-http: client: Make sure req->conn is only not NULL when that connection holds a reference to that request.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21424
diff
changeset
|
68 return http_client_request_unref(_req); |
70083e131e22
lib-http: client: Make sure req->conn is only not NULL when that connection holds a reference to that request.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21424
diff
changeset
|
69 } |
70083e131e22
lib-http: client: Make sure req->conn is only not NULL when that connection holds a reference to that request.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21424
diff
changeset
|
70 |
70083e131e22
lib-http: client: Make sure req->conn is only not NULL when that connection holds a reference to that request.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21424
diff
changeset
|
71 static inline void |
21029
a3a045122aa4
lib-http: client: Created http_client_connection_failure() handler.
Stephan Bosch <stephan@dovecot.fi>
parents:
21028
diff
changeset
|
72 http_client_connection_failure(struct http_client_connection *conn, |
a3a045122aa4
lib-http: client: Created http_client_connection_failure() handler.
Stephan Bosch <stephan@dovecot.fi>
parents:
21028
diff
changeset
|
73 const char *reason) |
a3a045122aa4
lib-http: client: Created http_client_connection_failure() handler.
Stephan Bosch <stephan@dovecot.fi>
parents:
21028
diff
changeset
|
74 { |
a3a045122aa4
lib-http: client: Created http_client_connection_failure() handler.
Stephan Bosch <stephan@dovecot.fi>
parents:
21028
diff
changeset
|
75 struct http_client_peer *peer = conn->peer; |
a3a045122aa4
lib-http: client: Created http_client_connection_failure() handler.
Stephan Bosch <stephan@dovecot.fi>
parents:
21028
diff
changeset
|
76 |
21333
f7bc77720fe5
lib-http: client: Consolidated connection loss handling into a single function.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21108
diff
changeset
|
77 conn->connect_failed = TRUE; |
21029
a3a045122aa4
lib-http: client: Created http_client_connection_failure() handler.
Stephan Bosch <stephan@dovecot.fi>
parents:
21028
diff
changeset
|
78 http_client_peer_connection_failure(peer, reason); |
a3a045122aa4
lib-http: client: Created http_client_connection_failure() handler.
Stephan Bosch <stephan@dovecot.fi>
parents:
21028
diff
changeset
|
79 } |
a3a045122aa4
lib-http: client: Created http_client_connection_failure() handler.
Stephan Bosch <stephan@dovecot.fi>
parents:
21028
diff
changeset
|
80 |
16566 | 81 unsigned int |
82 http_client_connection_count_pending(struct http_client_connection *conn) | |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
83 { |
16005
d3e3edf8f7eb
lib-http: Fixed hangs with urgent requests.
Timo Sirainen <tss@iki.fi>
parents:
16001
diff
changeset
|
84 unsigned int pending_count = array_count(&conn->request_wait_list); |
d3e3edf8f7eb
lib-http: Fixed hangs with urgent requests.
Timo Sirainen <tss@iki.fi>
parents:
16001
diff
changeset
|
85 |
17876
ecb0ba0ce02f
lib-http: client: Fixed problem occuring when a nested ioloop was run inside a request callback using the same client.
Stephan Bosch <stephan@rename-it.nl>
parents:
17857
diff
changeset
|
86 if (conn->in_req_callback || conn->pending_request != NULL) |
16005
d3e3edf8f7eb
lib-http: Fixed hangs with urgent requests.
Timo Sirainen <tss@iki.fi>
parents:
16001
diff
changeset
|
87 pending_count++; |
16566 | 88 return pending_count; |
89 } | |
90 | |
15710
c5230b8ffd40
lib-http: Various bugfixes
Stephan Bosch <stephan@rename-it.nl>
parents:
15579
diff
changeset
|
91 bool http_client_connection_is_idle(struct http_client_connection *conn) |
c5230b8ffd40
lib-http: Various bugfixes
Stephan Bosch <stephan@rename-it.nl>
parents:
15579
diff
changeset
|
92 { |
c5230b8ffd40
lib-http: Various bugfixes
Stephan Bosch <stephan@rename-it.nl>
parents:
15579
diff
changeset
|
93 return (conn->to_idle != NULL); |
c5230b8ffd40
lib-http: Various bugfixes
Stephan Bosch <stephan@rename-it.nl>
parents:
15579
diff
changeset
|
94 } |
c5230b8ffd40
lib-http: Various bugfixes
Stephan Bosch <stephan@rename-it.nl>
parents:
15579
diff
changeset
|
95 |
21030
8aa7fd1cff61
lib-http: client: Added function that checks whether a connection is currently active.
Stephan Bosch <stephan@dovecot.fi>
parents:
21029
diff
changeset
|
96 bool http_client_connection_is_active(struct http_client_connection *conn) |
8aa7fd1cff61
lib-http: client: Added function that checks whether a connection is currently active.
Stephan Bosch <stephan@dovecot.fi>
parents:
21029
diff
changeset
|
97 { |
8aa7fd1cff61
lib-http: client: Added function that checks whether a connection is currently active.
Stephan Bosch <stephan@dovecot.fi>
parents:
21029
diff
changeset
|
98 if (!conn->connected) |
8aa7fd1cff61
lib-http: client: Added function that checks whether a connection is currently active.
Stephan Bosch <stephan@dovecot.fi>
parents:
21029
diff
changeset
|
99 return FALSE; |
8aa7fd1cff61
lib-http: client: Added function that checks whether a connection is currently active.
Stephan Bosch <stephan@dovecot.fi>
parents:
21029
diff
changeset
|
100 |
8aa7fd1cff61
lib-http: client: Added function that checks whether a connection is currently active.
Stephan Bosch <stephan@dovecot.fi>
parents:
21029
diff
changeset
|
101 if (conn->in_req_callback || conn->pending_request != NULL) |
8aa7fd1cff61
lib-http: client: Added function that checks whether a connection is currently active.
Stephan Bosch <stephan@dovecot.fi>
parents:
21029
diff
changeset
|
102 return TRUE; |
8aa7fd1cff61
lib-http: client: Added function that checks whether a connection is currently active.
Stephan Bosch <stephan@dovecot.fi>
parents:
21029
diff
changeset
|
103 |
8aa7fd1cff61
lib-http: client: Added function that checks whether a connection is currently active.
Stephan Bosch <stephan@dovecot.fi>
parents:
21029
diff
changeset
|
104 return (array_is_created(&conn->request_wait_list) && |
8aa7fd1cff61
lib-http: client: Added function that checks whether a connection is currently active.
Stephan Bosch <stephan@dovecot.fi>
parents:
21029
diff
changeset
|
105 array_count(&conn->request_wait_list) > 0); |
8aa7fd1cff61
lib-http: client: Added function that checks whether a connection is currently active.
Stephan Bosch <stephan@dovecot.fi>
parents:
21029
diff
changeset
|
106 } |
8aa7fd1cff61
lib-http: client: Added function that checks whether a connection is currently active.
Stephan Bosch <stephan@dovecot.fi>
parents:
21029
diff
changeset
|
107 |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
108 static void |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
109 http_client_connection_retry_requests(struct http_client_connection *conn, |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
110 unsigned int status, const char *error) |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
111 { |
20364
51790e6d3310
lib-http: client: Implemented no_auto_retry setting that disables all automatic request retries.
Stephan Bosch <stephan@dovecot.fi>
parents:
20361
diff
changeset
|
112 const struct http_client_settings *set = &conn->client->set; |
20347
7e8ed1fa25bd
lib-http: client: Improved request reference counting in connection code.
Stephan Bosch <stephan@dovecot.fi>
parents:
20346
diff
changeset
|
113 struct http_client_request *req, **req_idx; |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
114 |
17773
bf371c4fed6e
lib-http: client: Tunnel connection failure would cause segfault.
Stephan Bosch <stephan@rename-it.nl>
parents:
17625
diff
changeset
|
115 if (!array_is_created(&conn->request_wait_list)) |
bf371c4fed6e
lib-http: client: Tunnel connection failure would cause segfault.
Stephan Bosch <stephan@rename-it.nl>
parents:
17625
diff
changeset
|
116 return; |
bf371c4fed6e
lib-http: client: Tunnel connection failure would cause segfault.
Stephan Bosch <stephan@rename-it.nl>
parents:
17625
diff
changeset
|
117 |
20364
51790e6d3310
lib-http: client: Implemented no_auto_retry setting that disables all automatic request retries.
Stephan Bosch <stephan@dovecot.fi>
parents:
20361
diff
changeset
|
118 if (set->no_auto_retry) { |
51790e6d3310
lib-http: client: Implemented no_auto_retry setting that disables all automatic request retries.
Stephan Bosch <stephan@dovecot.fi>
parents:
20361
diff
changeset
|
119 http_client_connection_debug(conn, |
51790e6d3310
lib-http: client: Implemented no_auto_retry setting that disables all automatic request retries.
Stephan Bosch <stephan@dovecot.fi>
parents:
20361
diff
changeset
|
120 "Aborting pending requests with error"); |
51790e6d3310
lib-http: client: Implemented no_auto_retry setting that disables all automatic request retries.
Stephan Bosch <stephan@dovecot.fi>
parents:
20361
diff
changeset
|
121 } else { |
51790e6d3310
lib-http: client: Implemented no_auto_retry setting that disables all automatic request retries.
Stephan Bosch <stephan@dovecot.fi>
parents:
20361
diff
changeset
|
122 http_client_connection_debug(conn, |
51790e6d3310
lib-http: client: Implemented no_auto_retry setting that disables all automatic request retries.
Stephan Bosch <stephan@dovecot.fi>
parents:
20361
diff
changeset
|
123 "Retrying pending requests"); |
51790e6d3310
lib-http: client: Implemented no_auto_retry setting that disables all automatic request retries.
Stephan Bosch <stephan@dovecot.fi>
parents:
20361
diff
changeset
|
124 } |
20347
7e8ed1fa25bd
lib-http: client: Improved request reference counting in connection code.
Stephan Bosch <stephan@dovecot.fi>
parents:
20346
diff
changeset
|
125 |
7e8ed1fa25bd
lib-http: client: Improved request reference counting in connection code.
Stephan Bosch <stephan@dovecot.fi>
parents:
20346
diff
changeset
|
126 array_foreach_modifiable(&conn->request_wait_list, req_idx) { |
7e8ed1fa25bd
lib-http: client: Improved request reference counting in connection code.
Stephan Bosch <stephan@dovecot.fi>
parents:
20346
diff
changeset
|
127 req = *req_idx; |
7e8ed1fa25bd
lib-http: client: Improved request reference counting in connection code.
Stephan Bosch <stephan@dovecot.fi>
parents:
20346
diff
changeset
|
128 /* drop reference from connection */ |
21425
70083e131e22
lib-http: client: Make sure req->conn is only not NULL when that connection holds a reference to that request.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21424
diff
changeset
|
129 if (!http_client_connection_unref_request(conn, req_idx)) |
20347
7e8ed1fa25bd
lib-http: client: Improved request reference counting in connection code.
Stephan Bosch <stephan@dovecot.fi>
parents:
20346
diff
changeset
|
130 continue; |
7e8ed1fa25bd
lib-http: client: Improved request reference counting in connection code.
Stephan Bosch <stephan@dovecot.fi>
parents:
20346
diff
changeset
|
131 /* retry the request, which may drop it */ |
20364
51790e6d3310
lib-http: client: Implemented no_auto_retry setting that disables all automatic request retries.
Stephan Bosch <stephan@dovecot.fi>
parents:
20361
diff
changeset
|
132 if (req->state < HTTP_REQUEST_STATE_FINISHED) { |
51790e6d3310
lib-http: client: Implemented no_auto_retry setting that disables all automatic request retries.
Stephan Bosch <stephan@dovecot.fi>
parents:
20361
diff
changeset
|
133 if (set->no_auto_retry) |
51790e6d3310
lib-http: client: Implemented no_auto_retry setting that disables all automatic request retries.
Stephan Bosch <stephan@dovecot.fi>
parents:
20361
diff
changeset
|
134 http_client_request_error(&req, status, error); |
51790e6d3310
lib-http: client: Implemented no_auto_retry setting that disables all automatic request retries.
Stephan Bosch <stephan@dovecot.fi>
parents:
20361
diff
changeset
|
135 else |
51790e6d3310
lib-http: client: Implemented no_auto_retry setting that disables all automatic request retries.
Stephan Bosch <stephan@dovecot.fi>
parents:
20361
diff
changeset
|
136 http_client_request_retry(req, status, error); |
51790e6d3310
lib-http: client: Implemented no_auto_retry setting that disables all automatic request retries.
Stephan Bosch <stephan@dovecot.fi>
parents:
20361
diff
changeset
|
137 } |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
138 } |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
139 array_clear(&conn->request_wait_list); |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
140 } |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
141 |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
142 static void |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
143 http_client_connection_server_close(struct http_client_connection **_conn) |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
144 { |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
145 struct http_client_connection *conn = *_conn; |
20347
7e8ed1fa25bd
lib-http: client: Improved request reference counting in connection code.
Stephan Bosch <stephan@dovecot.fi>
parents:
20346
diff
changeset
|
146 struct http_client_request *req, **req_idx; |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
147 |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
148 http_client_connection_debug(conn, |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
149 "Server explicitly closed connection"); |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
150 |
20347
7e8ed1fa25bd
lib-http: client: Improved request reference counting in connection code.
Stephan Bosch <stephan@dovecot.fi>
parents:
20346
diff
changeset
|
151 array_foreach_modifiable(&conn->request_wait_list, req_idx) { |
7e8ed1fa25bd
lib-http: client: Improved request reference counting in connection code.
Stephan Bosch <stephan@dovecot.fi>
parents:
20346
diff
changeset
|
152 req = *req_idx; |
7e8ed1fa25bd
lib-http: client: Improved request reference counting in connection code.
Stephan Bosch <stephan@dovecot.fi>
parents:
20346
diff
changeset
|
153 /* drop reference from connection */ |
21425
70083e131e22
lib-http: client: Make sure req->conn is only not NULL when that connection holds a reference to that request.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21424
diff
changeset
|
154 if (!http_client_connection_unref_request(conn, req_idx)) |
20347
7e8ed1fa25bd
lib-http: client: Improved request reference counting in connection code.
Stephan Bosch <stephan@dovecot.fi>
parents:
20346
diff
changeset
|
155 continue; |
7e8ed1fa25bd
lib-http: client: Improved request reference counting in connection code.
Stephan Bosch <stephan@dovecot.fi>
parents:
20346
diff
changeset
|
156 /* resubmit the request, which may drop it */ |
20473
a5a777e84bea
lib-http: client: Fixed potential segfault problem in http_client_connection_server_close().
Stephan Bosch <stephan@rename-it.nl>
parents:
20364
diff
changeset
|
157 if (req->state < HTTP_REQUEST_STATE_FINISHED) |
20347
7e8ed1fa25bd
lib-http: client: Improved request reference counting in connection code.
Stephan Bosch <stephan@dovecot.fi>
parents:
20346
diff
changeset
|
158 http_client_request_resubmit(req); |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
159 } |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
160 array_clear(&conn->request_wait_list); |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
161 |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
162 if (conn->client->ioloop != NULL) |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
163 io_loop_stop(conn->client->ioloop); |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
164 |
17968
c5f81685571f
lib-http: client: Fixed handling of connection timeouts.
Stephan Bosch <stephan@rename-it.nl>
parents:
17941
diff
changeset
|
165 http_client_connection_close(_conn); |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
166 } |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
167 |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
168 static void |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
169 http_client_connection_abort_error(struct http_client_connection **_conn, |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
170 unsigned int status, const char *error) |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
171 { |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
172 struct http_client_connection *conn = *_conn; |
20347
7e8ed1fa25bd
lib-http: client: Improved request reference counting in connection code.
Stephan Bosch <stephan@dovecot.fi>
parents:
20346
diff
changeset
|
173 struct http_client_request *req, **req_idx; |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
174 |
16574
a6b00756ab2c
lib-http: Added more debug messages.
Timo Sirainen <tss@iki.fi>
parents:
16572
diff
changeset
|
175 http_client_connection_debug(conn, "Aborting connection: %s", error); |
a6b00756ab2c
lib-http: Added more debug messages.
Timo Sirainen <tss@iki.fi>
parents:
16572
diff
changeset
|
176 |
20347
7e8ed1fa25bd
lib-http: client: Improved request reference counting in connection code.
Stephan Bosch <stephan@dovecot.fi>
parents:
20346
diff
changeset
|
177 array_foreach_modifiable(&conn->request_wait_list, req_idx) { |
7e8ed1fa25bd
lib-http: client: Improved request reference counting in connection code.
Stephan Bosch <stephan@dovecot.fi>
parents:
20346
diff
changeset
|
178 req = *req_idx; |
7e8ed1fa25bd
lib-http: client: Improved request reference counting in connection code.
Stephan Bosch <stephan@dovecot.fi>
parents:
20346
diff
changeset
|
179 i_assert(req->submitted); |
7e8ed1fa25bd
lib-http: client: Improved request reference counting in connection code.
Stephan Bosch <stephan@dovecot.fi>
parents:
20346
diff
changeset
|
180 /* drop reference from connection */ |
21425
70083e131e22
lib-http: client: Make sure req->conn is only not NULL when that connection holds a reference to that request.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21424
diff
changeset
|
181 if (!http_client_connection_unref_request(conn, req_idx)) |
20347
7e8ed1fa25bd
lib-http: client: Improved request reference counting in connection code.
Stephan Bosch <stephan@dovecot.fi>
parents:
20346
diff
changeset
|
182 continue; |
7e8ed1fa25bd
lib-http: client: Improved request reference counting in connection code.
Stephan Bosch <stephan@dovecot.fi>
parents:
20346
diff
changeset
|
183 /* drop request if not already aborted */ |
7e8ed1fa25bd
lib-http: client: Improved request reference counting in connection code.
Stephan Bosch <stephan@dovecot.fi>
parents:
20346
diff
changeset
|
184 http_client_request_error(&req, status, error); |
16267
79a74a23b742
lib-http: Don't double-free request memory when aborting them.
Timo Sirainen <tss@iki.fi>
parents:
16245
diff
changeset
|
185 } |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
186 array_clear(&conn->request_wait_list); |
17968
c5f81685571f
lib-http: client: Fixed handling of connection timeouts.
Stephan Bosch <stephan@rename-it.nl>
parents:
17941
diff
changeset
|
187 http_client_connection_close(_conn); |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
188 } |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
189 |
19726
f40f5e721744
lib-http: client: Make sure that any pending request is aborted and destroyed before connection FDs are closed.
Stephan Bosch <stephan@rename-it.nl>
parents:
19552
diff
changeset
|
190 static void |
f40f5e721744
lib-http: client: Make sure that any pending request is aborted and destroyed before connection FDs are closed.
Stephan Bosch <stephan@rename-it.nl>
parents:
19552
diff
changeset
|
191 http_client_connection_abort_any_requests(struct http_client_connection *conn) |
f40f5e721744
lib-http: client: Make sure that any pending request is aborted and destroyed before connection FDs are closed.
Stephan Bosch <stephan@rename-it.nl>
parents:
19552
diff
changeset
|
192 { |
20347
7e8ed1fa25bd
lib-http: client: Improved request reference counting in connection code.
Stephan Bosch <stephan@dovecot.fi>
parents:
20346
diff
changeset
|
193 struct http_client_request *req, **req_idx; |
19726
f40f5e721744
lib-http: client: Make sure that any pending request is aborted and destroyed before connection FDs are closed.
Stephan Bosch <stephan@rename-it.nl>
parents:
19552
diff
changeset
|
194 |
f40f5e721744
lib-http: client: Make sure that any pending request is aborted and destroyed before connection FDs are closed.
Stephan Bosch <stephan@rename-it.nl>
parents:
19552
diff
changeset
|
195 if (array_is_created(&conn->request_wait_list)) { |
20347
7e8ed1fa25bd
lib-http: client: Improved request reference counting in connection code.
Stephan Bosch <stephan@dovecot.fi>
parents:
20346
diff
changeset
|
196 array_foreach_modifiable(&conn->request_wait_list, req_idx) { |
7e8ed1fa25bd
lib-http: client: Improved request reference counting in connection code.
Stephan Bosch <stephan@dovecot.fi>
parents:
20346
diff
changeset
|
197 req = *req_idx; |
7e8ed1fa25bd
lib-http: client: Improved request reference counting in connection code.
Stephan Bosch <stephan@dovecot.fi>
parents:
20346
diff
changeset
|
198 i_assert(req->submitted); |
7e8ed1fa25bd
lib-http: client: Improved request reference counting in connection code.
Stephan Bosch <stephan@dovecot.fi>
parents:
20346
diff
changeset
|
199 /* drop reference from connection */ |
21425
70083e131e22
lib-http: client: Make sure req->conn is only not NULL when that connection holds a reference to that request.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21424
diff
changeset
|
200 if (!http_client_connection_unref_request(conn, req_idx)) |
20347
7e8ed1fa25bd
lib-http: client: Improved request reference counting in connection code.
Stephan Bosch <stephan@dovecot.fi>
parents:
20346
diff
changeset
|
201 continue; |
7e8ed1fa25bd
lib-http: client: Improved request reference counting in connection code.
Stephan Bosch <stephan@dovecot.fi>
parents:
20346
diff
changeset
|
202 /* drop request if not already aborted */ |
7e8ed1fa25bd
lib-http: client: Improved request reference counting in connection code.
Stephan Bosch <stephan@dovecot.fi>
parents:
20346
diff
changeset
|
203 http_client_request_error(&req, |
19726
f40f5e721744
lib-http: client: Make sure that any pending request is aborted and destroyed before connection FDs are closed.
Stephan Bosch <stephan@rename-it.nl>
parents:
19552
diff
changeset
|
204 HTTP_CLIENT_REQUEST_ERROR_ABORTED, |
f40f5e721744
lib-http: client: Make sure that any pending request is aborted and destroyed before connection FDs are closed.
Stephan Bosch <stephan@rename-it.nl>
parents:
19552
diff
changeset
|
205 "Aborting"); |
f40f5e721744
lib-http: client: Make sure that any pending request is aborted and destroyed before connection FDs are closed.
Stephan Bosch <stephan@rename-it.nl>
parents:
19552
diff
changeset
|
206 } |
f40f5e721744
lib-http: client: Make sure that any pending request is aborted and destroyed before connection FDs are closed.
Stephan Bosch <stephan@rename-it.nl>
parents:
19552
diff
changeset
|
207 array_clear(&conn->request_wait_list); |
f40f5e721744
lib-http: client: Make sure that any pending request is aborted and destroyed before connection FDs are closed.
Stephan Bosch <stephan@rename-it.nl>
parents:
19552
diff
changeset
|
208 } |
f40f5e721744
lib-http: client: Make sure that any pending request is aborted and destroyed before connection FDs are closed.
Stephan Bosch <stephan@rename-it.nl>
parents:
19552
diff
changeset
|
209 if (conn->pending_request != NULL) { |
20347
7e8ed1fa25bd
lib-http: client: Improved request reference counting in connection code.
Stephan Bosch <stephan@dovecot.fi>
parents:
20346
diff
changeset
|
210 req = conn->pending_request; |
7e8ed1fa25bd
lib-http: client: Improved request reference counting in connection code.
Stephan Bosch <stephan@dovecot.fi>
parents:
20346
diff
changeset
|
211 /* drop reference from connection */ |
21425
70083e131e22
lib-http: client: Make sure req->conn is only not NULL when that connection holds a reference to that request.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21424
diff
changeset
|
212 if (http_client_connection_unref_request(conn, &conn->pending_request)) { |
20347
7e8ed1fa25bd
lib-http: client: Improved request reference counting in connection code.
Stephan Bosch <stephan@dovecot.fi>
parents:
20346
diff
changeset
|
213 /* drop request if not already aborted */ |
7e8ed1fa25bd
lib-http: client: Improved request reference counting in connection code.
Stephan Bosch <stephan@dovecot.fi>
parents:
20346
diff
changeset
|
214 http_client_request_error(&req, |
7e8ed1fa25bd
lib-http: client: Improved request reference counting in connection code.
Stephan Bosch <stephan@dovecot.fi>
parents:
20346
diff
changeset
|
215 HTTP_CLIENT_REQUEST_ERROR_ABORTED, |
7e8ed1fa25bd
lib-http: client: Improved request reference counting in connection code.
Stephan Bosch <stephan@dovecot.fi>
parents:
20346
diff
changeset
|
216 "Aborting"); |
7e8ed1fa25bd
lib-http: client: Improved request reference counting in connection code.
Stephan Bosch <stephan@dovecot.fi>
parents:
20346
diff
changeset
|
217 } |
19726
f40f5e721744
lib-http: client: Make sure that any pending request is aborted and destroyed before connection FDs are closed.
Stephan Bosch <stephan@rename-it.nl>
parents:
19552
diff
changeset
|
218 } |
f40f5e721744
lib-http: client: Make sure that any pending request is aborted and destroyed before connection FDs are closed.
Stephan Bosch <stephan@rename-it.nl>
parents:
19552
diff
changeset
|
219 } |
f40f5e721744
lib-http: client: Make sure that any pending request is aborted and destroyed before connection FDs are closed.
Stephan Bosch <stephan@rename-it.nl>
parents:
19552
diff
changeset
|
220 |
19524
3df66d89a87a
lib-http: Add more timing information to debug logs when HTTP connections get closed.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19461
diff
changeset
|
221 static const char * |
3df66d89a87a
lib-http: Add more timing information to debug logs when HTTP connections get closed.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19461
diff
changeset
|
222 http_client_connection_get_timing_info(struct http_client_connection *conn) |
3df66d89a87a
lib-http: Add more timing information to debug logs when HTTP connections get closed.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19461
diff
changeset
|
223 { |
3df66d89a87a
lib-http: Add more timing information to debug logs when HTTP connections get closed.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19461
diff
changeset
|
224 struct http_client_request *const *requestp; |
21874
02be39ae109d
lib-http: client: Implemented means to obtain request statistics.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21856
diff
changeset
|
225 unsigned int connected_msecs; |
19524
3df66d89a87a
lib-http: Add more timing information to debug logs when HTTP connections get closed.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19461
diff
changeset
|
226 string_t *str = t_str_new(64); |
3df66d89a87a
lib-http: Add more timing information to debug logs when HTTP connections get closed.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19461
diff
changeset
|
227 |
3df66d89a87a
lib-http: Add more timing information to debug logs when HTTP connections get closed.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19461
diff
changeset
|
228 if (array_count(&conn->request_wait_list) > 0) { |
3df66d89a87a
lib-http: Add more timing information to debug logs when HTTP connections get closed.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19461
diff
changeset
|
229 requestp = array_idx(&conn->request_wait_list, 0); |
3df66d89a87a
lib-http: Add more timing information to debug logs when HTTP connections get closed.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19461
diff
changeset
|
230 |
21874
02be39ae109d
lib-http: client: Implemented means to obtain request statistics.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21856
diff
changeset
|
231 str_append(str, "Request "); |
02be39ae109d
lib-http: client: Implemented means to obtain request statistics.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21856
diff
changeset
|
232 http_client_request_append_stats_text(*requestp, str); |
19524
3df66d89a87a
lib-http: Add more timing information to debug logs when HTTP connections get closed.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19461
diff
changeset
|
233 } else { |
3df66d89a87a
lib-http: Add more timing information to debug logs when HTTP connections get closed.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19461
diff
changeset
|
234 str_append(str, "No requests"); |
3df66d89a87a
lib-http: Add more timing information to debug logs when HTTP connections get closed.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19461
diff
changeset
|
235 if (conn->conn.last_input != 0) { |
3df66d89a87a
lib-http: Add more timing information to debug logs when HTTP connections get closed.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19461
diff
changeset
|
236 str_printfa(str, ", last input %d secs ago", |
3df66d89a87a
lib-http: Add more timing information to debug logs when HTTP connections get closed.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19461
diff
changeset
|
237 (int)(ioloop_time - conn->conn.last_input)); |
3df66d89a87a
lib-http: Add more timing information to debug logs when HTTP connections get closed.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19461
diff
changeset
|
238 } |
3df66d89a87a
lib-http: Add more timing information to debug logs when HTTP connections get closed.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19461
diff
changeset
|
239 } |
3df66d89a87a
lib-http: Add more timing information to debug logs when HTTP connections get closed.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19461
diff
changeset
|
240 connected_msecs = timeval_diff_msecs(&ioloop_timeval, &conn->connected_timestamp); |
3df66d89a87a
lib-http: Add more timing information to debug logs when HTTP connections get closed.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19461
diff
changeset
|
241 str_printfa(str, ", connected %u.%03u secs ago", |
3df66d89a87a
lib-http: Add more timing information to debug logs when HTTP connections get closed.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19461
diff
changeset
|
242 connected_msecs/1000, connected_msecs%1000); |
3df66d89a87a
lib-http: Add more timing information to debug logs when HTTP connections get closed.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19461
diff
changeset
|
243 return str_c(str); |
3df66d89a87a
lib-http: Add more timing information to debug logs when HTTP connections get closed.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19461
diff
changeset
|
244 } |
3df66d89a87a
lib-http: Add more timing information to debug logs when HTTP connections get closed.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19461
diff
changeset
|
245 |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
246 static void |
16245
ac0e59dfe081
lib-http: If remote SSL cert is invalid, treat it as non-retryable error.
Timo Sirainen <tss@iki.fi>
parents:
16236
diff
changeset
|
247 http_client_connection_abort_temp_error(struct http_client_connection **_conn, |
ac0e59dfe081
lib-http: If remote SSL cert is invalid, treat it as non-retryable error.
Timo Sirainen <tss@iki.fi>
parents:
16236
diff
changeset
|
248 unsigned int status, const char *error) |
ac0e59dfe081
lib-http: If remote SSL cert is invalid, treat it as non-retryable error.
Timo Sirainen <tss@iki.fi>
parents:
16236
diff
changeset
|
249 { |
ac0e59dfe081
lib-http: If remote SSL cert is invalid, treat it as non-retryable error.
Timo Sirainen <tss@iki.fi>
parents:
16236
diff
changeset
|
250 struct http_client_connection *conn = *_conn; |
21333
f7bc77720fe5
lib-http: client: Consolidated connection loss handling into a single function.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21108
diff
changeset
|
251 |
f7bc77720fe5
lib-http: client: Consolidated connection loss handling into a single function.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21108
diff
changeset
|
252 error = t_strdup_printf("%s (%s)", error, |
f7bc77720fe5
lib-http: client: Consolidated connection loss handling into a single function.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21108
diff
changeset
|
253 http_client_connection_get_timing_info(conn)); |
f7bc77720fe5
lib-http: client: Consolidated connection loss handling into a single function.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21108
diff
changeset
|
254 |
f7bc77720fe5
lib-http: client: Consolidated connection loss handling into a single function.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21108
diff
changeset
|
255 http_client_connection_debug(conn, |
f7bc77720fe5
lib-http: client: Consolidated connection loss handling into a single function.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21108
diff
changeset
|
256 "Aborting connection with temporary error: %s", error); |
f7bc77720fe5
lib-http: client: Consolidated connection loss handling into a single function.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21108
diff
changeset
|
257 |
f7bc77720fe5
lib-http: client: Consolidated connection loss handling into a single function.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21108
diff
changeset
|
258 http_client_connection_retry_requests(conn, status, error); |
f7bc77720fe5
lib-http: client: Consolidated connection loss handling into a single function.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21108
diff
changeset
|
259 http_client_connection_close(_conn); |
f7bc77720fe5
lib-http: client: Consolidated connection loss handling into a single function.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21108
diff
changeset
|
260 } |
f7bc77720fe5
lib-http: client: Consolidated connection loss handling into a single function.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21108
diff
changeset
|
261 |
f7bc77720fe5
lib-http: client: Consolidated connection loss handling into a single function.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21108
diff
changeset
|
262 static void |
f7bc77720fe5
lib-http: client: Consolidated connection loss handling into a single function.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21108
diff
changeset
|
263 http_client_connection_lost(struct http_client_connection **_conn, |
f7bc77720fe5
lib-http: client: Consolidated connection loss handling into a single function.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21108
diff
changeset
|
264 const char *error) ATTR_NULL(2) |
f7bc77720fe5
lib-http: client: Consolidated connection loss handling into a single function.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21108
diff
changeset
|
265 { |
f7bc77720fe5
lib-http: client: Consolidated connection loss handling into a single function.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21108
diff
changeset
|
266 struct http_client_connection *conn = *_conn; |
16245
ac0e59dfe081
lib-http: If remote SSL cert is invalid, treat it as non-retryable error.
Timo Sirainen <tss@iki.fi>
parents:
16236
diff
changeset
|
267 const char *sslerr; |
ac0e59dfe081
lib-http: If remote SSL cert is invalid, treat it as non-retryable error.
Timo Sirainen <tss@iki.fi>
parents:
16236
diff
changeset
|
268 |
21333
f7bc77720fe5
lib-http: client: Consolidated connection loss handling into a single function.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21108
diff
changeset
|
269 if (error == NULL) |
f7bc77720fe5
lib-http: client: Consolidated connection loss handling into a single function.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21108
diff
changeset
|
270 error = "Connection lost"; |
f7bc77720fe5
lib-http: client: Consolidated connection loss handling into a single function.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21108
diff
changeset
|
271 else |
f7bc77720fe5
lib-http: client: Consolidated connection loss handling into a single function.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21108
diff
changeset
|
272 error = t_strdup_printf("Connection lost: %s", error); |
f7bc77720fe5
lib-http: client: Consolidated connection loss handling into a single function.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21108
diff
changeset
|
273 |
f7bc77720fe5
lib-http: client: Consolidated connection loss handling into a single function.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21108
diff
changeset
|
274 if (conn->ssl_iostream != NULL) { |
16245
ac0e59dfe081
lib-http: If remote SSL cert is invalid, treat it as non-retryable error.
Timo Sirainen <tss@iki.fi>
parents:
16236
diff
changeset
|
275 sslerr = ssl_iostream_get_last_error(conn->ssl_iostream); |
ac0e59dfe081
lib-http: If remote SSL cert is invalid, treat it as non-retryable error.
Timo Sirainen <tss@iki.fi>
parents:
16236
diff
changeset
|
276 if (sslerr != NULL) { |
ac0e59dfe081
lib-http: If remote SSL cert is invalid, treat it as non-retryable error.
Timo Sirainen <tss@iki.fi>
parents:
16236
diff
changeset
|
277 error = t_strdup_printf("%s (last SSL error: %s)", |
ac0e59dfe081
lib-http: If remote SSL cert is invalid, treat it as non-retryable error.
Timo Sirainen <tss@iki.fi>
parents:
16236
diff
changeset
|
278 error, sslerr); |
ac0e59dfe081
lib-http: If remote SSL cert is invalid, treat it as non-retryable error.
Timo Sirainen <tss@iki.fi>
parents:
16236
diff
changeset
|
279 } |
ac0e59dfe081
lib-http: If remote SSL cert is invalid, treat it as non-retryable error.
Timo Sirainen <tss@iki.fi>
parents:
16236
diff
changeset
|
280 if (ssl_iostream_has_handshake_failed(conn->ssl_iostream)) { |
ac0e59dfe081
lib-http: If remote SSL cert is invalid, treat it as non-retryable error.
Timo Sirainen <tss@iki.fi>
parents:
16236
diff
changeset
|
281 /* this isn't really a "connection lost", but that we |
ac0e59dfe081
lib-http: If remote SSL cert is invalid, treat it as non-retryable error.
Timo Sirainen <tss@iki.fi>
parents:
16236
diff
changeset
|
282 don't trust the remote's SSL certificate. don't |
ac0e59dfe081
lib-http: If remote SSL cert is invalid, treat it as non-retryable error.
Timo Sirainen <tss@iki.fi>
parents:
16236
diff
changeset
|
283 retry. */ |
ac0e59dfe081
lib-http: If remote SSL cert is invalid, treat it as non-retryable error.
Timo Sirainen <tss@iki.fi>
parents:
16236
diff
changeset
|
284 http_client_connection_abort_error(_conn, |
ac0e59dfe081
lib-http: If remote SSL cert is invalid, treat it as non-retryable error.
Timo Sirainen <tss@iki.fi>
parents:
16236
diff
changeset
|
285 HTTP_CLIENT_REQUEST_ERROR_BAD_RESPONSE, error); |
ac0e59dfe081
lib-http: If remote SSL cert is invalid, treat it as non-retryable error.
Timo Sirainen <tss@iki.fi>
parents:
16236
diff
changeset
|
286 return; |
ac0e59dfe081
lib-http: If remote SSL cert is invalid, treat it as non-retryable error.
Timo Sirainen <tss@iki.fi>
parents:
16236
diff
changeset
|
287 } |
ac0e59dfe081
lib-http: If remote SSL cert is invalid, treat it as non-retryable error.
Timo Sirainen <tss@iki.fi>
parents:
16236
diff
changeset
|
288 } |
ac0e59dfe081
lib-http: If remote SSL cert is invalid, treat it as non-retryable error.
Timo Sirainen <tss@iki.fi>
parents:
16236
diff
changeset
|
289 |
21334
919df3038bf5
lib-http: client: Treat connections that get disconnected prematurely as connection failures.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21333
diff
changeset
|
290 conn->lost_prematurely = (conn->conn.input != NULL && |
919df3038bf5
lib-http: client: Treat connections that get disconnected prematurely as connection failures.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21333
diff
changeset
|
291 conn->conn.input->v_offset == 0 && |
919df3038bf5
lib-http: client: Treat connections that get disconnected prematurely as connection failures.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21333
diff
changeset
|
292 i_stream_get_data_size(conn->conn.input) == 0); |
21333
f7bc77720fe5
lib-http: client: Consolidated connection loss handling into a single function.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21108
diff
changeset
|
293 http_client_connection_abort_temp_error(_conn, |
f7bc77720fe5
lib-http: client: Consolidated connection loss handling into a single function.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21108
diff
changeset
|
294 HTTP_CLIENT_REQUEST_ERROR_CONNECTION_LOST, error); |
16245
ac0e59dfe081
lib-http: If remote SSL cert is invalid, treat it as non-retryable error.
Timo Sirainen <tss@iki.fi>
parents:
16236
diff
changeset
|
295 } |
ac0e59dfe081
lib-http: If remote SSL cert is invalid, treat it as non-retryable error.
Timo Sirainen <tss@iki.fi>
parents:
16236
diff
changeset
|
296 |
20355
6335d6256a58
lib-http: client: Fixed bug in handling of lost connections while returning from another ioloop.
Stephan Bosch <stephan@dovecot.fi>
parents:
20354
diff
changeset
|
297 int http_client_connection_check_ready(struct http_client_connection *conn) |
17882
77c4b78a4fa2
lib-http: Fixed detecting disconnection when ioloop is running only intermittently.
Stephan Bosch <stephan@rename-it.nl>
parents:
17881
diff
changeset
|
298 { |
77c4b78a4fa2
lib-http: Fixed detecting disconnection when ioloop is running only intermittently.
Stephan Bosch <stephan@rename-it.nl>
parents:
17881
diff
changeset
|
299 int ret; |
77c4b78a4fa2
lib-http: Fixed detecting disconnection when ioloop is running only intermittently.
Stephan Bosch <stephan@rename-it.nl>
parents:
17881
diff
changeset
|
300 |
77c4b78a4fa2
lib-http: Fixed detecting disconnection when ioloop is running only intermittently.
Stephan Bosch <stephan@rename-it.nl>
parents:
17881
diff
changeset
|
301 if (conn->in_req_callback) { |
77c4b78a4fa2
lib-http: Fixed detecting disconnection when ioloop is running only intermittently.
Stephan Bosch <stephan@rename-it.nl>
parents:
17881
diff
changeset
|
302 /* this can happen when a nested ioloop is created inside request |
77c4b78a4fa2
lib-http: Fixed detecting disconnection when ioloop is running only intermittently.
Stephan Bosch <stephan@rename-it.nl>
parents:
17881
diff
changeset
|
303 callback. we currently don't reuse connections that are occupied |
77c4b78a4fa2
lib-http: Fixed detecting disconnection when ioloop is running only intermittently.
Stephan Bosch <stephan@rename-it.nl>
parents:
17881
diff
changeset
|
304 this way, but theoretically we could, although that would add |
77c4b78a4fa2
lib-http: Fixed detecting disconnection when ioloop is running only intermittently.
Stephan Bosch <stephan@rename-it.nl>
parents:
17881
diff
changeset
|
305 quite a bit of complexity. |
77c4b78a4fa2
lib-http: Fixed detecting disconnection when ioloop is running only intermittently.
Stephan Bosch <stephan@rename-it.nl>
parents:
17881
diff
changeset
|
306 */ |
20355
6335d6256a58
lib-http: client: Fixed bug in handling of lost connections while returning from another ioloop.
Stephan Bosch <stephan@dovecot.fi>
parents:
20354
diff
changeset
|
307 return 0; |
17882
77c4b78a4fa2
lib-http: Fixed detecting disconnection when ioloop is running only intermittently.
Stephan Bosch <stephan@rename-it.nl>
parents:
17881
diff
changeset
|
308 } |
77c4b78a4fa2
lib-http: Fixed detecting disconnection when ioloop is running only intermittently.
Stephan Bosch <stephan@rename-it.nl>
parents:
17881
diff
changeset
|
309 |
18001
cffa8349f167
lib-http: client: Fixed handling of requests aborted while still sending payload to server.
Stephan Bosch <stephan@rename-it.nl>
parents:
17999
diff
changeset
|
310 if (!conn->connected || conn->output_locked || conn->output_broken || |
17882
77c4b78a4fa2
lib-http: Fixed detecting disconnection when ioloop is running only intermittently.
Stephan Bosch <stephan@rename-it.nl>
parents:
17881
diff
changeset
|
311 conn->close_indicated || conn->tunneling || |
77c4b78a4fa2
lib-http: Fixed detecting disconnection when ioloop is running only intermittently.
Stephan Bosch <stephan@rename-it.nl>
parents:
17881
diff
changeset
|
312 http_client_connection_count_pending(conn) >= |
77c4b78a4fa2
lib-http: Fixed detecting disconnection when ioloop is running only intermittently.
Stephan Bosch <stephan@rename-it.nl>
parents:
17881
diff
changeset
|
313 conn->client->set.max_pipelined_requests) |
20355
6335d6256a58
lib-http: client: Fixed bug in handling of lost connections while returning from another ioloop.
Stephan Bosch <stephan@dovecot.fi>
parents:
20354
diff
changeset
|
314 return 0; |
17882
77c4b78a4fa2
lib-http: Fixed detecting disconnection when ioloop is running only intermittently.
Stephan Bosch <stephan@rename-it.nl>
parents:
17881
diff
changeset
|
315 |
77c4b78a4fa2
lib-http: Fixed detecting disconnection when ioloop is running only intermittently.
Stephan Bosch <stephan@rename-it.nl>
parents:
17881
diff
changeset
|
316 if (conn->last_ioloop != NULL && conn->last_ioloop != current_ioloop) { |
77c4b78a4fa2
lib-http: Fixed detecting disconnection when ioloop is running only intermittently.
Stephan Bosch <stephan@rename-it.nl>
parents:
17881
diff
changeset
|
317 conn->last_ioloop = current_ioloop; |
77c4b78a4fa2
lib-http: Fixed detecting disconnection when ioloop is running only intermittently.
Stephan Bosch <stephan@rename-it.nl>
parents:
17881
diff
changeset
|
318 /* Active ioloop is different from what we saw earlier; |
77c4b78a4fa2
lib-http: Fixed detecting disconnection when ioloop is running only intermittently.
Stephan Bosch <stephan@rename-it.nl>
parents:
17881
diff
changeset
|
319 we may have missed a disconnection event on this connection. |
77c4b78a4fa2
lib-http: Fixed detecting disconnection when ioloop is running only intermittently.
Stephan Bosch <stephan@rename-it.nl>
parents:
17881
diff
changeset
|
320 Verify status by reading from connection. */ |
18026
69af57dcd274
lib-http: client: Removed asssert in http_client_connection_is_ready().
Stephan Bosch <stephan@rename-it.nl>
parents:
18025
diff
changeset
|
321 if ((ret=i_stream_read(conn->conn.input)) == -1) { |
17882
77c4b78a4fa2
lib-http: Fixed detecting disconnection when ioloop is running only intermittently.
Stephan Bosch <stephan@rename-it.nl>
parents:
17881
diff
changeset
|
322 int stream_errno = conn->conn.input->stream_errno; |
77c4b78a4fa2
lib-http: Fixed detecting disconnection when ioloop is running only intermittently.
Stephan Bosch <stephan@rename-it.nl>
parents:
17881
diff
changeset
|
323 |
77c4b78a4fa2
lib-http: Fixed detecting disconnection when ioloop is running only intermittently.
Stephan Bosch <stephan@rename-it.nl>
parents:
17881
diff
changeset
|
324 i_assert(conn->conn.input->stream_errno != 0 || conn->conn.input->eof); |
21333
f7bc77720fe5
lib-http: client: Consolidated connection loss handling into a single function.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21108
diff
changeset
|
325 http_client_connection_lost(&conn, |
f7bc77720fe5
lib-http: client: Consolidated connection loss handling into a single function.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21108
diff
changeset
|
326 t_strdup_printf("read(%s) failed: %s", |
17882
77c4b78a4fa2
lib-http: Fixed detecting disconnection when ioloop is running only intermittently.
Stephan Bosch <stephan@rename-it.nl>
parents:
17881
diff
changeset
|
327 i_stream_get_name(conn->conn.input), |
77c4b78a4fa2
lib-http: Fixed detecting disconnection when ioloop is running only intermittently.
Stephan Bosch <stephan@rename-it.nl>
parents:
17881
diff
changeset
|
328 stream_errno != 0 ? |
77c4b78a4fa2
lib-http: Fixed detecting disconnection when ioloop is running only intermittently.
Stephan Bosch <stephan@rename-it.nl>
parents:
17881
diff
changeset
|
329 i_stream_get_error(conn->conn.input) : |
77c4b78a4fa2
lib-http: Fixed detecting disconnection when ioloop is running only intermittently.
Stephan Bosch <stephan@rename-it.nl>
parents:
17881
diff
changeset
|
330 "EOF")); |
20355
6335d6256a58
lib-http: client: Fixed bug in handling of lost connections while returning from another ioloop.
Stephan Bosch <stephan@dovecot.fi>
parents:
20354
diff
changeset
|
331 return -1; |
17882
77c4b78a4fa2
lib-http: Fixed detecting disconnection when ioloop is running only intermittently.
Stephan Bosch <stephan@rename-it.nl>
parents:
17881
diff
changeset
|
332 } |
20742
ff4c5d5ee76f
lib-http: client: Fixed hang occurring when nested ioloops are used in response callbacks.
Stephan Bosch <stephan@dovecot.fi>
parents:
20584
diff
changeset
|
333 |
ff4c5d5ee76f
lib-http: client: Fixed hang occurring when nested ioloops are used in response callbacks.
Stephan Bosch <stephan@dovecot.fi>
parents:
20584
diff
changeset
|
334 /* we may have read some data */ |
ff4c5d5ee76f
lib-http: client: Fixed hang occurring when nested ioloops are used in response callbacks.
Stephan Bosch <stephan@dovecot.fi>
parents:
20584
diff
changeset
|
335 if (i_stream_get_data_size(conn->conn.input) > 0) |
ff4c5d5ee76f
lib-http: client: Fixed hang occurring when nested ioloops are used in response callbacks.
Stephan Bosch <stephan@dovecot.fi>
parents:
20584
diff
changeset
|
336 i_stream_set_input_pending(conn->conn.input, TRUE); |
17882
77c4b78a4fa2
lib-http: Fixed detecting disconnection when ioloop is running only intermittently.
Stephan Bosch <stephan@rename-it.nl>
parents:
17881
diff
changeset
|
337 } |
20355
6335d6256a58
lib-http: client: Fixed bug in handling of lost connections while returning from another ioloop.
Stephan Bosch <stephan@dovecot.fi>
parents:
20354
diff
changeset
|
338 return 1; |
17882
77c4b78a4fa2
lib-http: Fixed detecting disconnection when ioloop is running only intermittently.
Stephan Bosch <stephan@rename-it.nl>
parents:
17881
diff
changeset
|
339 } |
77c4b78a4fa2
lib-http: Fixed detecting disconnection when ioloop is running only intermittently.
Stephan Bosch <stephan@rename-it.nl>
parents:
17881
diff
changeset
|
340 |
16245
ac0e59dfe081
lib-http: If remote SSL cert is invalid, treat it as non-retryable error.
Timo Sirainen <tss@iki.fi>
parents:
16236
diff
changeset
|
341 static void |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
342 http_client_connection_idle_timeout(struct http_client_connection *conn) |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
343 { |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
344 http_client_connection_debug(conn, "Idle connection timed out"); |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
345 |
17610
320a224ad353
lib-http: Made sure that connections that are still connecting to the server aren't marked as idle.
Stephan Bosch <stephan@rename-it.nl>
parents:
17549
diff
changeset
|
346 /* cannot get here unless connection was established at some point */ |
320a224ad353
lib-http: Made sure that connections that are still connecting to the server aren't marked as idle.
Stephan Bosch <stephan@rename-it.nl>
parents:
17549
diff
changeset
|
347 i_assert(conn->connect_succeeded); |
320a224ad353
lib-http: Made sure that connections that are still connecting to the server aren't marked as idle.
Stephan Bosch <stephan@rename-it.nl>
parents:
17549
diff
changeset
|
348 |
17968
c5f81685571f
lib-http: client: Fixed handling of connection timeouts.
Stephan Bosch <stephan@rename-it.nl>
parents:
17941
diff
changeset
|
349 http_client_connection_close(&conn); |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
350 } |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
351 |
16733
bdc5d6dcfc53
lib-http: http-client: Fixed request scheduling and connection management.
Stephan Bosch <stephan@rename-it.nl>
parents:
16731
diff
changeset
|
352 void http_client_connection_check_idle(struct http_client_connection *conn) |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
353 { |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
354 unsigned int timeout, count; |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
355 |
17610
320a224ad353
lib-http: Made sure that connections that are still connecting to the server aren't marked as idle.
Stephan Bosch <stephan@rename-it.nl>
parents:
17549
diff
changeset
|
356 if (conn->connected && |
320a224ad353
lib-http: Made sure that connections that are still connecting to the server aren't marked as idle.
Stephan Bosch <stephan@rename-it.nl>
parents:
17549
diff
changeset
|
357 array_is_created(&conn->request_wait_list) && |
16855
c3884a6acde6
lib-http: Added support for creating CONNECT tunnels through HTTP.
Stephan Bosch <stephan@rename-it.nl>
parents:
16852
diff
changeset
|
358 array_count(&conn->request_wait_list) == 0 && |
17876
ecb0ba0ce02f
lib-http: client: Fixed problem occuring when a nested ioloop was run inside a request callback using the same client.
Stephan Bosch <stephan@rename-it.nl>
parents:
17857
diff
changeset
|
359 !conn->in_req_callback && |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
360 conn->incoming_payload == NULL && |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
361 conn->client->set.max_idle_time_msecs > 0) { |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
362 |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
363 if (conn->to_idle != NULL) { |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
364 /* timeout already set */ |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
365 return; |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
366 } |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
367 |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
368 if (conn->client->ioloop != NULL) |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
369 io_loop_stop(conn->client->ioloop); |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
370 |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
371 count = array_count(&conn->peer->conns); |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
372 i_assert(count > 0); |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
373 |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
374 /* set timeout for this connection */ |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
375 if (count > conn->client->set.max_parallel_connections) { |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
376 /* instant death for (urgent) connections above limit */ |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
377 timeout = 0; |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
378 } else { |
15710
c5230b8ffd40
lib-http: Various bugfixes
Stephan Bosch <stephan@rename-it.nl>
parents:
15579
diff
changeset
|
379 unsigned int idle_count = http_client_peer_idle_connections(conn->peer); |
c5230b8ffd40
lib-http: Various bugfixes
Stephan Bosch <stephan@rename-it.nl>
parents:
15579
diff
changeset
|
380 |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
381 /* kill duplicate connections quicker; |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
382 linearly based on the number of connections */ |
15710
c5230b8ffd40
lib-http: Various bugfixes
Stephan Bosch <stephan@rename-it.nl>
parents:
15579
diff
changeset
|
383 i_assert(count >= idle_count + 1); |
c5230b8ffd40
lib-http: Various bugfixes
Stephan Bosch <stephan@rename-it.nl>
parents:
15579
diff
changeset
|
384 timeout = (conn->client->set.max_parallel_connections - idle_count) * |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
385 (conn->client->set.max_idle_time_msecs / |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
386 conn->client->set.max_parallel_connections); |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
387 } |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
388 |
15710
c5230b8ffd40
lib-http: Various bugfixes
Stephan Bosch <stephan@rename-it.nl>
parents:
15579
diff
changeset
|
389 http_client_connection_debug(conn, |
c5230b8ffd40
lib-http: Various bugfixes
Stephan Bosch <stephan@rename-it.nl>
parents:
15579
diff
changeset
|
390 "No more requests queued; going idle (timeout = %u msecs)", |
c5230b8ffd40
lib-http: Various bugfixes
Stephan Bosch <stephan@rename-it.nl>
parents:
15579
diff
changeset
|
391 timeout); |
c5230b8ffd40
lib-http: Various bugfixes
Stephan Bosch <stephan@rename-it.nl>
parents:
15579
diff
changeset
|
392 |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
393 conn->to_idle = |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
394 timeout_add(timeout, http_client_connection_idle_timeout, conn); |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
395 |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
396 } else { |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
397 /* there should be no idle timeout */ |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
398 i_assert(conn->to_idle == NULL); |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
399 } |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
400 } |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
401 |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
402 static void |
16451
a551409911f9
lib-http: Added connect and request timeout settings.
Timo Sirainen <tss@iki.fi>
parents:
16450
diff
changeset
|
403 http_client_connection_request_timeout(struct http_client_connection *conn) |
a551409911f9
lib-http: Added connect and request timeout settings.
Timo Sirainen <tss@iki.fi>
parents:
16450
diff
changeset
|
404 { |
16569
3fdfbabf3dcf
lib-http: If connection times out, set the stream's errno to ETIMEDOUT in case it's used.
Timo Sirainen <tss@iki.fi>
parents:
16568
diff
changeset
|
405 conn->conn.input->stream_errno = ETIMEDOUT; |
16451
a551409911f9
lib-http: Added connect and request timeout settings.
Timo Sirainen <tss@iki.fi>
parents:
16450
diff
changeset
|
406 http_client_connection_abort_temp_error(&conn, |
19524
3df66d89a87a
lib-http: Add more timing information to debug logs when HTTP connections get closed.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19461
diff
changeset
|
407 HTTP_CLIENT_REQUEST_ERROR_TIMED_OUT, "Request timed out"); |
16451
a551409911f9
lib-http: Added connect and request timeout settings.
Timo Sirainen <tss@iki.fi>
parents:
16450
diff
changeset
|
408 } |
a551409911f9
lib-http: Added connect and request timeout settings.
Timo Sirainen <tss@iki.fi>
parents:
16450
diff
changeset
|
409 |
18969
a08e79a3707f
lib-http: client: Fixed handling of request timeout.
Stephan Bosch <stephan@rename-it.nl>
parents:
18494
diff
changeset
|
410 void http_client_connection_start_request_timeout( |
a08e79a3707f
lib-http: client: Fixed handling of request timeout.
Stephan Bosch <stephan@rename-it.nl>
parents:
18494
diff
changeset
|
411 struct http_client_connection *conn) |
a08e79a3707f
lib-http: client: Fixed handling of request timeout.
Stephan Bosch <stephan@rename-it.nl>
parents:
18494
diff
changeset
|
412 { |
20584
6ff9cfbbdf4c
lib-http: Support per-request timeout and max_attempts
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20473
diff
changeset
|
413 unsigned int timeout_msecs = |
6ff9cfbbdf4c
lib-http: Support per-request timeout and max_attempts
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20473
diff
changeset
|
414 conn->client->set.request_timeout_msecs; |
18969
a08e79a3707f
lib-http: client: Fixed handling of request timeout.
Stephan Bosch <stephan@rename-it.nl>
parents:
18494
diff
changeset
|
415 |
21856
a0112b13e73c
lib-http: client: Fixed request-specific attempt timeout.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21788
diff
changeset
|
416 if (conn->pending_request != NULL) |
a0112b13e73c
lib-http: client: Fixed request-specific attempt timeout.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21788
diff
changeset
|
417 return; |
a0112b13e73c
lib-http: client: Fixed request-specific attempt timeout.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21788
diff
changeset
|
418 |
a0112b13e73c
lib-http: client: Fixed request-specific attempt timeout.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21788
diff
changeset
|
419 i_assert(array_is_created(&conn->request_wait_list)); |
a0112b13e73c
lib-http: client: Fixed request-specific attempt timeout.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21788
diff
changeset
|
420 if (array_count(&conn->request_wait_list) > 0) { |
a0112b13e73c
lib-http: client: Fixed request-specific attempt timeout.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21788
diff
changeset
|
421 struct http_client_request *const *requestp; |
a0112b13e73c
lib-http: client: Fixed request-specific attempt timeout.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21788
diff
changeset
|
422 requestp = array_idx(&conn->request_wait_list, 0); |
a0112b13e73c
lib-http: client: Fixed request-specific attempt timeout.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21788
diff
changeset
|
423 timeout_msecs = (*requestp)->attempt_timeout_msecs; |
a0112b13e73c
lib-http: client: Fixed request-specific attempt timeout.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21788
diff
changeset
|
424 } |
a0112b13e73c
lib-http: client: Fixed request-specific attempt timeout.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21788
diff
changeset
|
425 |
18969
a08e79a3707f
lib-http: client: Fixed handling of request timeout.
Stephan Bosch <stephan@rename-it.nl>
parents:
18494
diff
changeset
|
426 if (timeout_msecs == 0) |
a08e79a3707f
lib-http: client: Fixed handling of request timeout.
Stephan Bosch <stephan@rename-it.nl>
parents:
18494
diff
changeset
|
427 ; |
a08e79a3707f
lib-http: client: Fixed handling of request timeout.
Stephan Bosch <stephan@rename-it.nl>
parents:
18494
diff
changeset
|
428 else if (conn->to_requests != NULL) |
a08e79a3707f
lib-http: client: Fixed handling of request timeout.
Stephan Bosch <stephan@rename-it.nl>
parents:
18494
diff
changeset
|
429 timeout_reset(conn->to_requests); |
a08e79a3707f
lib-http: client: Fixed handling of request timeout.
Stephan Bosch <stephan@rename-it.nl>
parents:
18494
diff
changeset
|
430 else { |
a08e79a3707f
lib-http: client: Fixed handling of request timeout.
Stephan Bosch <stephan@rename-it.nl>
parents:
18494
diff
changeset
|
431 conn->to_requests = timeout_add(timeout_msecs, |
a08e79a3707f
lib-http: client: Fixed handling of request timeout.
Stephan Bosch <stephan@rename-it.nl>
parents:
18494
diff
changeset
|
432 http_client_connection_request_timeout, conn); |
a08e79a3707f
lib-http: client: Fixed handling of request timeout.
Stephan Bosch <stephan@rename-it.nl>
parents:
18494
diff
changeset
|
433 } |
a08e79a3707f
lib-http: client: Fixed handling of request timeout.
Stephan Bosch <stephan@rename-it.nl>
parents:
18494
diff
changeset
|
434 } |
a08e79a3707f
lib-http: client: Fixed handling of request timeout.
Stephan Bosch <stephan@rename-it.nl>
parents:
18494
diff
changeset
|
435 |
a08e79a3707f
lib-http: client: Fixed handling of request timeout.
Stephan Bosch <stephan@rename-it.nl>
parents:
18494
diff
changeset
|
436 void http_client_connection_reset_request_timeout( |
a08e79a3707f
lib-http: client: Fixed handling of request timeout.
Stephan Bosch <stephan@rename-it.nl>
parents:
18494
diff
changeset
|
437 struct http_client_connection *conn) |
a08e79a3707f
lib-http: client: Fixed handling of request timeout.
Stephan Bosch <stephan@rename-it.nl>
parents:
18494
diff
changeset
|
438 { |
a08e79a3707f
lib-http: client: Fixed handling of request timeout.
Stephan Bosch <stephan@rename-it.nl>
parents:
18494
diff
changeset
|
439 if (conn->to_requests != NULL) |
a08e79a3707f
lib-http: client: Fixed handling of request timeout.
Stephan Bosch <stephan@rename-it.nl>
parents:
18494
diff
changeset
|
440 timeout_reset(conn->to_requests); |
a08e79a3707f
lib-http: client: Fixed handling of request timeout.
Stephan Bosch <stephan@rename-it.nl>
parents:
18494
diff
changeset
|
441 } |
a08e79a3707f
lib-http: client: Fixed handling of request timeout.
Stephan Bosch <stephan@rename-it.nl>
parents:
18494
diff
changeset
|
442 |
a08e79a3707f
lib-http: client: Fixed handling of request timeout.
Stephan Bosch <stephan@rename-it.nl>
parents:
18494
diff
changeset
|
443 void http_client_connection_stop_request_timeout( |
a08e79a3707f
lib-http: client: Fixed handling of request timeout.
Stephan Bosch <stephan@rename-it.nl>
parents:
18494
diff
changeset
|
444 struct http_client_connection *conn) |
a08e79a3707f
lib-http: client: Fixed handling of request timeout.
Stephan Bosch <stephan@rename-it.nl>
parents:
18494
diff
changeset
|
445 { |
a08e79a3707f
lib-http: client: Fixed handling of request timeout.
Stephan Bosch <stephan@rename-it.nl>
parents:
18494
diff
changeset
|
446 if (conn->to_requests != NULL) |
a08e79a3707f
lib-http: client: Fixed handling of request timeout.
Stephan Bosch <stephan@rename-it.nl>
parents:
18494
diff
changeset
|
447 timeout_remove(&conn->to_requests); |
a08e79a3707f
lib-http: client: Fixed handling of request timeout.
Stephan Bosch <stephan@rename-it.nl>
parents:
18494
diff
changeset
|
448 } |
a08e79a3707f
lib-http: client: Fixed handling of request timeout.
Stephan Bosch <stephan@rename-it.nl>
parents:
18494
diff
changeset
|
449 |
16451
a551409911f9
lib-http: Added connect and request timeout settings.
Timo Sirainen <tss@iki.fi>
parents:
16450
diff
changeset
|
450 static void |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
451 http_client_connection_continue_timeout(struct http_client_connection *conn) |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
452 { |
19961
3f6a74b9ce54
lib-http: client: Fixed request timeout handling during pipelining.
Stephan Bosch <stephan@rename-it.nl>
parents:
19937
diff
changeset
|
453 struct http_client_request *const *wait_reqs; |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
454 struct http_client_request *req; |
19961
3f6a74b9ce54
lib-http: client: Fixed request timeout handling during pipelining.
Stephan Bosch <stephan@rename-it.nl>
parents:
19937
diff
changeset
|
455 unsigned int wait_count; |
15999
f89ebdc1625d
lib-http: If we get disconnected, say exactly what the error was.
Timo Sirainen <tss@iki.fi>
parents:
15879
diff
changeset
|
456 const char *error; |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
457 |
19961
3f6a74b9ce54
lib-http: client: Fixed request timeout handling during pipelining.
Stephan Bosch <stephan@rename-it.nl>
parents:
19937
diff
changeset
|
458 i_assert(conn->pending_request == NULL); |
3f6a74b9ce54
lib-http: client: Fixed request timeout handling during pipelining.
Stephan Bosch <stephan@rename-it.nl>
parents:
19937
diff
changeset
|
459 |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
460 if (conn->to_response != NULL) |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
461 timeout_remove(&conn->to_response); |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
462 conn->peer->no_payload_sync = TRUE; |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
463 |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
464 http_client_connection_debug(conn, |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
465 "Expected 100-continue response timed out; sending payload anyway"); |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
466 |
19961
3f6a74b9ce54
lib-http: client: Fixed request timeout handling during pipelining.
Stephan Bosch <stephan@rename-it.nl>
parents:
19937
diff
changeset
|
467 wait_reqs = array_get(&conn->request_wait_list, &wait_count); |
3f6a74b9ce54
lib-http: client: Fixed request timeout handling during pipelining.
Stephan Bosch <stephan@rename-it.nl>
parents:
19937
diff
changeset
|
468 i_assert(wait_count == 1); |
3f6a74b9ce54
lib-http: client: Fixed request timeout handling during pipelining.
Stephan Bosch <stephan@rename-it.nl>
parents:
19937
diff
changeset
|
469 req = wait_reqs[wait_count-1]; |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
470 |
19727
8f72e4f0ed5d
lib-http: client: Fixed pipelining bug: client sometimes sent new request while still waiting for 100-continue.
Stephan Bosch <stephan@rename-it.nl>
parents:
19726
diff
changeset
|
471 req->payload_sync_continue = TRUE; |
19961
3f6a74b9ce54
lib-http: client: Fixed request timeout handling during pipelining.
Stephan Bosch <stephan@rename-it.nl>
parents:
19937
diff
changeset
|
472 if (http_client_request_send_more(req, FALSE, &error) < 0) { |
21333
f7bc77720fe5
lib-http: client: Consolidated connection loss handling into a single function.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21108
diff
changeset
|
473 http_client_connection_lost(&conn, |
15999
f89ebdc1625d
lib-http: If we get disconnected, say exactly what the error was.
Timo Sirainen <tss@iki.fi>
parents:
15879
diff
changeset
|
474 t_strdup_printf("Failed to send request: %s", error)); |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
475 } |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
476 } |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
477 |
16733
bdc5d6dcfc53
lib-http: http-client: Fixed request scheduling and connection management.
Stephan Bosch <stephan@rename-it.nl>
parents:
16731
diff
changeset
|
478 int http_client_connection_next_request(struct http_client_connection *conn) |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
479 { |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
480 struct http_client_request *req = NULL; |
15999
f89ebdc1625d
lib-http: If we get disconnected, say exactly what the error was.
Timo Sirainen <tss@iki.fi>
parents:
15879
diff
changeset
|
481 const char *error; |
19961
3f6a74b9ce54
lib-http: client: Fixed request timeout handling during pipelining.
Stephan Bosch <stephan@rename-it.nl>
parents:
19937
diff
changeset
|
482 bool pipelined; |
20355
6335d6256a58
lib-http: client: Fixed bug in handling of lost connections while returning from another ioloop.
Stephan Bosch <stephan@dovecot.fi>
parents:
20354
diff
changeset
|
483 int ret; |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
484 |
20355
6335d6256a58
lib-http: client: Fixed bug in handling of lost connections while returning from another ioloop.
Stephan Bosch <stephan@dovecot.fi>
parents:
20354
diff
changeset
|
485 if ((ret=http_client_connection_check_ready(conn)) <= 0) { |
6335d6256a58
lib-http: client: Fixed bug in handling of lost connections while returning from another ioloop.
Stephan Bosch <stephan@dovecot.fi>
parents:
20354
diff
changeset
|
486 if (ret == 0) { |
6335d6256a58
lib-http: client: Fixed bug in handling of lost connections while returning from another ioloop.
Stephan Bosch <stephan@dovecot.fi>
parents:
20354
diff
changeset
|
487 http_client_connection_debug(conn, |
6335d6256a58
lib-http: client: Fixed bug in handling of lost connections while returning from another ioloop.
Stephan Bosch <stephan@dovecot.fi>
parents:
20354
diff
changeset
|
488 "Not ready for next request"); |
6335d6256a58
lib-http: client: Fixed bug in handling of lost connections while returning from another ioloop.
Stephan Bosch <stephan@dovecot.fi>
parents:
20354
diff
changeset
|
489 } |
6335d6256a58
lib-http: client: Fixed bug in handling of lost connections while returning from another ioloop.
Stephan Bosch <stephan@dovecot.fi>
parents:
20354
diff
changeset
|
490 return ret; |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
491 } |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
492 |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
493 /* claim request, but no urgent request can be second in line */ |
19961
3f6a74b9ce54
lib-http: client: Fixed request timeout handling during pipelining.
Stephan Bosch <stephan@rename-it.nl>
parents:
19937
diff
changeset
|
494 pipelined = array_count(&conn->request_wait_list) > 0 || |
16005
d3e3edf8f7eb
lib-http: Fixed hangs with urgent requests.
Timo Sirainen <tss@iki.fi>
parents:
16001
diff
changeset
|
495 conn->pending_request != NULL; |
19961
3f6a74b9ce54
lib-http: client: Fixed request timeout handling during pipelining.
Stephan Bosch <stephan@rename-it.nl>
parents:
19937
diff
changeset
|
496 req = http_client_peer_claim_request(conn->peer, pipelined); |
16733
bdc5d6dcfc53
lib-http: http-client: Fixed request scheduling and connection management.
Stephan Bosch <stephan@rename-it.nl>
parents:
16731
diff
changeset
|
497 if (req == NULL) |
bdc5d6dcfc53
lib-http: http-client: Fixed request scheduling and connection management.
Stephan Bosch <stephan@rename-it.nl>
parents:
16731
diff
changeset
|
498 return 0; |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
499 |
18001
cffa8349f167
lib-http: client: Fixed handling of requests aborted while still sending payload to server.
Stephan Bosch <stephan@rename-it.nl>
parents:
17999
diff
changeset
|
500 i_assert(req->state == HTTP_REQUEST_STATE_QUEUED); |
cffa8349f167
lib-http: client: Fixed handling of requests aborted while still sending payload to server.
Stephan Bosch <stephan@rename-it.nl>
parents:
17999
diff
changeset
|
501 |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
502 if (conn->to_idle != NULL) |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
503 timeout_remove(&conn->to_idle); |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
504 |
19727
8f72e4f0ed5d
lib-http: client: Fixed pipelining bug: client sometimes sent new request while still waiting for 100-continue.
Stephan Bosch <stephan@rename-it.nl>
parents:
19726
diff
changeset
|
505 req->payload_sync_continue = FALSE; |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
506 if (conn->peer->no_payload_sync) |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
507 req->payload_sync = FALSE; |
15579 | 508 |
20347
7e8ed1fa25bd
lib-http: client: Improved request reference counting in connection code.
Stephan Bosch <stephan@dovecot.fi>
parents:
20346
diff
changeset
|
509 /* add request to wait list and add a reference */ |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
510 array_append(&conn->request_wait_list, &req, 1); |
21425
70083e131e22
lib-http: client: Make sure req->conn is only not NULL when that connection holds a reference to that request.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21424
diff
changeset
|
511 http_client_connection_ref_request(conn, req); |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
512 |
15710
c5230b8ffd40
lib-http: Various bugfixes
Stephan Bosch <stephan@rename-it.nl>
parents:
15579
diff
changeset
|
513 http_client_connection_debug(conn, "Claimed request %s", |
c5230b8ffd40
lib-http: Various bugfixes
Stephan Bosch <stephan@rename-it.nl>
parents:
15579
diff
changeset
|
514 http_client_request_label(req)); |
c5230b8ffd40
lib-http: Various bugfixes
Stephan Bosch <stephan@rename-it.nl>
parents:
15579
diff
changeset
|
515 |
19961
3f6a74b9ce54
lib-http: client: Fixed request timeout handling during pipelining.
Stephan Bosch <stephan@rename-it.nl>
parents:
19937
diff
changeset
|
516 if (http_client_request_send(req, pipelined, &error) < 0) { |
21333
f7bc77720fe5
lib-http: client: Consolidated connection loss handling into a single function.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21108
diff
changeset
|
517 http_client_connection_lost(&conn, |
15999
f89ebdc1625d
lib-http: If we get disconnected, say exactly what the error was.
Timo Sirainen <tss@iki.fi>
parents:
15879
diff
changeset
|
518 t_strdup_printf("Failed to send request: %s", error)); |
16733
bdc5d6dcfc53
lib-http: http-client: Fixed request scheduling and connection management.
Stephan Bosch <stephan@rename-it.nl>
parents:
16731
diff
changeset
|
519 return -1; |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
520 } |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
521 |
16855
c3884a6acde6
lib-http: Added support for creating CONNECT tunnels through HTTP.
Stephan Bosch <stephan@rename-it.nl>
parents:
16852
diff
changeset
|
522 if (req->connect_tunnel) |
c3884a6acde6
lib-http: Added support for creating CONNECT tunnels through HTTP.
Stephan Bosch <stephan@rename-it.nl>
parents:
16852
diff
changeset
|
523 conn->tunneling = TRUE; |
c3884a6acde6
lib-http: Added support for creating CONNECT tunnels through HTTP.
Stephan Bosch <stephan@rename-it.nl>
parents:
16852
diff
changeset
|
524 |
17549
9511372c7c18
lib-http: Updated comments to RFC7230/RFC7231.
Stephan Bosch <stephan@rename-it.nl>
parents:
17521
diff
changeset
|
525 /* RFC 7231, Section 5.1.1: Expect |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
526 |
17549
9511372c7c18
lib-http: Updated comments to RFC7230/RFC7231.
Stephan Bosch <stephan@rename-it.nl>
parents:
17521
diff
changeset
|
527 o A client that sends a 100-continue expectation is not required to |
9511372c7c18
lib-http: Updated comments to RFC7230/RFC7231.
Stephan Bosch <stephan@rename-it.nl>
parents:
17521
diff
changeset
|
528 wait for any specific length of time; such a client MAY proceed to |
9511372c7c18
lib-http: Updated comments to RFC7230/RFC7231.
Stephan Bosch <stephan@rename-it.nl>
parents:
17521
diff
changeset
|
529 send the message body even if it has not yet received a response. |
9511372c7c18
lib-http: Updated comments to RFC7230/RFC7231.
Stephan Bosch <stephan@rename-it.nl>
parents:
17521
diff
changeset
|
530 Furthermore, since 100 (Continue) responses cannot be sent through |
9511372c7c18
lib-http: Updated comments to RFC7230/RFC7231.
Stephan Bosch <stephan@rename-it.nl>
parents:
17521
diff
changeset
|
531 an HTTP/1.0 intermediary, such a client SHOULD NOT wait for an |
9511372c7c18
lib-http: Updated comments to RFC7230/RFC7231.
Stephan Bosch <stephan@rename-it.nl>
parents:
17521
diff
changeset
|
532 indefinite period before sending the message body. |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
533 */ |
16453
bcf93c30a500
lib-http: After peer has received 100 response, don't add ambiguity timeout anymore.
Timo Sirainen <tss@iki.fi>
parents:
16452
diff
changeset
|
534 if (req->payload_sync && !conn->peer->seen_100_response) { |
19961
3f6a74b9ce54
lib-http: client: Fixed request timeout handling during pipelining.
Stephan Bosch <stephan@rename-it.nl>
parents:
19937
diff
changeset
|
535 i_assert(!pipelined); |
15710
c5230b8ffd40
lib-http: Various bugfixes
Stephan Bosch <stephan@rename-it.nl>
parents:
15579
diff
changeset
|
536 i_assert(req->payload_chunked || req->payload_size > 0); |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
537 i_assert(conn->to_response == NULL); |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
538 conn->to_response = timeout_add(HTTP_CLIENT_CONTINUE_TIMEOUT_MSECS, |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
539 http_client_connection_continue_timeout, conn); |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
540 } |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
541 |
16733
bdc5d6dcfc53
lib-http: http-client: Fixed request scheduling and connection management.
Stephan Bosch <stephan@rename-it.nl>
parents:
16731
diff
changeset
|
542 return 1; |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
543 } |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
544 |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
545 static void http_client_connection_destroy(struct connection *_conn) |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
546 { |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
547 struct http_client_connection *conn = |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
548 (struct http_client_connection *)_conn; |
16000
00ee7a8306c7
lib-http: Fixed crash caused by previous change.
Timo Sirainen <tss@iki.fi>
parents:
15999
diff
changeset
|
549 const char *error; |
16451
a551409911f9
lib-http: Added connect and request timeout settings.
Timo Sirainen <tss@iki.fi>
parents:
16450
diff
changeset
|
550 unsigned int msecs; |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
551 |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
552 switch (_conn->disconnect_reason) { |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
553 case CONNECTION_DISCONNECT_CONNECT_TIMEOUT: |
16451
a551409911f9
lib-http: Added connect and request timeout settings.
Timo Sirainen <tss@iki.fi>
parents:
16450
diff
changeset
|
554 if (conn->connected_timestamp.tv_sec == 0) { |
a551409911f9
lib-http: Added connect and request timeout settings.
Timo Sirainen <tss@iki.fi>
parents:
16450
diff
changeset
|
555 msecs = timeval_diff_msecs(&ioloop_timeval, |
a551409911f9
lib-http: Added connect and request timeout settings.
Timo Sirainen <tss@iki.fi>
parents:
16450
diff
changeset
|
556 &conn->connect_start_timestamp); |
16460
452cecc7e708
lib-http: Treat connect() timeouts as retryable errors.
Timo Sirainen <tss@iki.fi>
parents:
16459
diff
changeset
|
557 error = t_strdup_printf( |
16451
a551409911f9
lib-http: Added connect and request timeout settings.
Timo Sirainen <tss@iki.fi>
parents:
16450
diff
changeset
|
558 "connect(%s) failed: Connection timed out in %u.%03u secs", |
16460
452cecc7e708
lib-http: Treat connect() timeouts as retryable errors.
Timo Sirainen <tss@iki.fi>
parents:
16459
diff
changeset
|
559 _conn->name, msecs/1000, msecs%1000); |
16451
a551409911f9
lib-http: Added connect and request timeout settings.
Timo Sirainen <tss@iki.fi>
parents:
16450
diff
changeset
|
560 } else { |
a551409911f9
lib-http: Added connect and request timeout settings.
Timo Sirainen <tss@iki.fi>
parents:
16450
diff
changeset
|
561 msecs = timeval_diff_msecs(&ioloop_timeval, |
a551409911f9
lib-http: Added connect and request timeout settings.
Timo Sirainen <tss@iki.fi>
parents:
16450
diff
changeset
|
562 &conn->connected_timestamp); |
16460
452cecc7e708
lib-http: Treat connect() timeouts as retryable errors.
Timo Sirainen <tss@iki.fi>
parents:
16459
diff
changeset
|
563 error = t_strdup_printf( |
17970
7d3325713356
lib-http: client: Connection erroneously indicated that it was ready while SSL handshake was not yet completed.
Stephan Bosch <stephan@rename-it.nl>
parents:
17968
diff
changeset
|
564 "SSL handshaking with %s failed: Connection timed out in %u.%03u secs", |
16460
452cecc7e708
lib-http: Treat connect() timeouts as retryable errors.
Timo Sirainen <tss@iki.fi>
parents:
16459
diff
changeset
|
565 _conn->name, msecs/1000, msecs%1000); |
16451
a551409911f9
lib-http: Added connect and request timeout settings.
Timo Sirainen <tss@iki.fi>
parents:
16450
diff
changeset
|
566 } |
16574
a6b00756ab2c
lib-http: Added more debug messages.
Timo Sirainen <tss@iki.fi>
parents:
16572
diff
changeset
|
567 http_client_connection_debug(conn, "%s", error); |
21029
a3a045122aa4
lib-http: client: Created http_client_connection_failure() handler.
Stephan Bosch <stephan@dovecot.fi>
parents:
21028
diff
changeset
|
568 http_client_connection_failure(conn, error); |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
569 break; |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
570 case CONNECTION_DISCONNECT_CONN_CLOSED: |
21333
f7bc77720fe5
lib-http: client: Consolidated connection loss handling into a single function.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21108
diff
changeset
|
571 if (conn->connect_failed) { |
f7bc77720fe5
lib-http: client: Consolidated connection loss handling into a single function.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21108
diff
changeset
|
572 i_assert(!array_is_created(&conn->request_wait_list) || |
f7bc77720fe5
lib-http: client: Consolidated connection loss handling into a single function.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21108
diff
changeset
|
573 array_count(&conn->request_wait_list) == 0); |
f7bc77720fe5
lib-http: client: Consolidated connection loss handling into a single function.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21108
diff
changeset
|
574 break; |
f7bc77720fe5
lib-http: client: Consolidated connection loss handling into a single function.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21108
diff
changeset
|
575 } |
f7bc77720fe5
lib-http: client: Consolidated connection loss handling into a single function.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21108
diff
changeset
|
576 http_client_connection_lost(&conn, |
f7bc77720fe5
lib-http: client: Consolidated connection loss handling into a single function.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21108
diff
changeset
|
577 (_conn->input == NULL ? NULL : |
f7bc77720fe5
lib-http: client: Consolidated connection loss handling into a single function.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21108
diff
changeset
|
578 i_stream_get_error(_conn->input))); |
f7bc77720fe5
lib-http: client: Consolidated connection loss handling into a single function.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21108
diff
changeset
|
579 return; |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
580 default: |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
581 break; |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
582 } |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
583 |
17968
c5f81685571f
lib-http: client: Fixed handling of connection timeouts.
Stephan Bosch <stephan@rename-it.nl>
parents:
17941
diff
changeset
|
584 http_client_connection_close(&conn); |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
585 } |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
586 |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
587 static void http_client_payload_finished(struct http_client_connection *conn) |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
588 { |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
589 timeout_remove(&conn->to_input); |
17192
a1c153c70bb9
Use io_add_istream() wherever possible.
Timo Sirainen <tss@iki.fi>
parents:
17191
diff
changeset
|
590 conn->conn.io = io_add_istream(conn->conn.input, |
a1c153c70bb9
Use io_add_istream() wherever possible.
Timo Sirainen <tss@iki.fi>
parents:
17191
diff
changeset
|
591 http_client_connection_input, &conn->conn); |
19961
3f6a74b9ce54
lib-http: client: Fixed request timeout handling during pipelining.
Stephan Bosch <stephan@rename-it.nl>
parents:
19937
diff
changeset
|
592 if (array_count(&conn->request_wait_list) > 0) |
3f6a74b9ce54
lib-http: client: Fixed request timeout handling during pipelining.
Stephan Bosch <stephan@rename-it.nl>
parents:
19937
diff
changeset
|
593 http_client_connection_start_request_timeout(conn); |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
594 } |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
595 |
15440
9cab24687819
lib-http: Don't free connection immediately in payload-destroyed callback.
Timo Sirainen <tss@iki.fi>
parents:
15394
diff
changeset
|
596 static void |
9cab24687819
lib-http: Don't free connection immediately in payload-destroyed callback.
Timo Sirainen <tss@iki.fi>
parents:
15394
diff
changeset
|
597 http_client_payload_destroyed_timeout(struct http_client_connection *conn) |
9cab24687819
lib-http: Don't free connection immediately in payload-destroyed callback.
Timo Sirainen <tss@iki.fi>
parents:
15394
diff
changeset
|
598 { |
9cab24687819
lib-http: Don't free connection immediately in payload-destroyed callback.
Timo Sirainen <tss@iki.fi>
parents:
15394
diff
changeset
|
599 if (conn->close_indicated) { |
9cab24687819
lib-http: Don't free connection immediately in payload-destroyed callback.
Timo Sirainen <tss@iki.fi>
parents:
15394
diff
changeset
|
600 http_client_connection_server_close(&conn); |
9cab24687819
lib-http: Don't free connection immediately in payload-destroyed callback.
Timo Sirainen <tss@iki.fi>
parents:
15394
diff
changeset
|
601 return; |
9cab24687819
lib-http: Don't free connection immediately in payload-destroyed callback.
Timo Sirainen <tss@iki.fi>
parents:
15394
diff
changeset
|
602 } |
9cab24687819
lib-http: Don't free connection immediately in payload-destroyed callback.
Timo Sirainen <tss@iki.fi>
parents:
15394
diff
changeset
|
603 http_client_connection_input(&conn->conn); |
9cab24687819
lib-http: Don't free connection immediately in payload-destroyed callback.
Timo Sirainen <tss@iki.fi>
parents:
15394
diff
changeset
|
604 } |
9cab24687819
lib-http: Don't free connection immediately in payload-destroyed callback.
Timo Sirainen <tss@iki.fi>
parents:
15394
diff
changeset
|
605 |
16005
d3e3edf8f7eb
lib-http: Fixed hangs with urgent requests.
Timo Sirainen <tss@iki.fi>
parents:
16001
diff
changeset
|
606 static void http_client_payload_destroyed(struct http_client_request *req) |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
607 { |
16005
d3e3edf8f7eb
lib-http: Fixed hangs with urgent requests.
Timo Sirainen <tss@iki.fi>
parents:
16001
diff
changeset
|
608 struct http_client_connection *conn = req->conn; |
d3e3edf8f7eb
lib-http: Fixed hangs with urgent requests.
Timo Sirainen <tss@iki.fi>
parents:
16001
diff
changeset
|
609 |
16855
c3884a6acde6
lib-http: Added support for creating CONNECT tunnels through HTTP.
Stephan Bosch <stephan@rename-it.nl>
parents:
16852
diff
changeset
|
610 i_assert(conn != NULL); |
16005
d3e3edf8f7eb
lib-http: Fixed hangs with urgent requests.
Timo Sirainen <tss@iki.fi>
parents:
16001
diff
changeset
|
611 i_assert(conn->pending_request == req); |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
612 i_assert(conn->incoming_payload != NULL); |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
613 i_assert(conn->conn.io == NULL); |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
614 |
17625
b162e39909d7
lib-http: Debug log now includes where HTTP requests spent their time on.
Timo Sirainen <tss@iki.fi>
parents:
17610
diff
changeset
|
615 http_client_connection_debug(conn, |
b162e39909d7
lib-http: Debug log now includes where HTTP requests spent their time on.
Timo Sirainen <tss@iki.fi>
parents:
17610
diff
changeset
|
616 "Response payload stream destroyed (%u ms after initial response)", |
b162e39909d7
lib-http: Debug log now includes where HTTP requests spent their time on.
Timo Sirainen <tss@iki.fi>
parents:
17610
diff
changeset
|
617 timeval_diff_msecs(&ioloop_timeval, &req->response_time)); |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
618 |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
619 /* caller is allowed to change the socket fd to blocking while reading |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
620 the payload. make sure here that it's switched back. */ |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
621 net_set_nonblock(conn->conn.fd_in, TRUE); |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
622 |
20347
7e8ed1fa25bd
lib-http: client: Improved request reference counting in connection code.
Stephan Bosch <stephan@dovecot.fi>
parents:
20346
diff
changeset
|
623 /* drop reference from connection */ |
21425
70083e131e22
lib-http: client: Make sure req->conn is only not NULL when that connection holds a reference to that request.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21424
diff
changeset
|
624 if (http_client_connection_unref_request(conn, &conn->pending_request)) { |
20347
7e8ed1fa25bd
lib-http: client: Improved request reference counting in connection code.
Stephan Bosch <stephan@dovecot.fi>
parents:
20346
diff
changeset
|
625 /* finish request if not already aborted */ |
7e8ed1fa25bd
lib-http: client: Improved request reference counting in connection code.
Stephan Bosch <stephan@dovecot.fi>
parents:
20346
diff
changeset
|
626 http_client_request_finish(req); |
7e8ed1fa25bd
lib-http: client: Improved request reference counting in connection code.
Stephan Bosch <stephan@dovecot.fi>
parents:
20346
diff
changeset
|
627 } |
7e8ed1fa25bd
lib-http: client: Improved request reference counting in connection code.
Stephan Bosch <stephan@dovecot.fi>
parents:
20346
diff
changeset
|
628 |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
629 conn->incoming_payload = NULL; |
17276
6895214e33cf
lib-http: Fixed problem with connections idling indefinitely.
Stephan Bosch <stephan@rename-it.nl>
parents:
17192
diff
changeset
|
630 |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
631 /* input stream may have pending input. make sure input handler |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
632 gets called (but don't do it directly, since we get get here |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
633 somewhere from the API user's code, which we can't really know what |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
634 state it is in). this call also triggers sending a new request if |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
635 necessary. */ |
20354
adfa1b7fea65
lib-http: client: Reworked connection close handling.
Stephan Bosch <stephan@dovecot.fi>
parents:
20352
diff
changeset
|
636 if (!conn->disconnected) { |
adfa1b7fea65
lib-http: client: Reworked connection close handling.
Stephan Bosch <stephan@dovecot.fi>
parents:
20352
diff
changeset
|
637 conn->to_input = timeout_add_short |
adfa1b7fea65
lib-http: client: Reworked connection close handling.
Stephan Bosch <stephan@dovecot.fi>
parents:
20352
diff
changeset
|
638 (0, http_client_payload_destroyed_timeout, conn); |
adfa1b7fea65
lib-http: client: Reworked connection close handling.
Stephan Bosch <stephan@dovecot.fi>
parents:
20352
diff
changeset
|
639 } |
17881
4f175c27bea5
lib-http: client: Added support for absolute request timeout.
Stephan Bosch <stephan@rename-it.nl>
parents:
17876
diff
changeset
|
640 |
20347
7e8ed1fa25bd
lib-http: client: Improved request reference counting in connection code.
Stephan Bosch <stephan@dovecot.fi>
parents:
20346
diff
changeset
|
641 /* room for new requests */ |
20355
6335d6256a58
lib-http: client: Fixed bug in handling of lost connections while returning from another ioloop.
Stephan Bosch <stephan@dovecot.fi>
parents:
20354
diff
changeset
|
642 if (http_client_connection_check_ready(conn) > 0) |
20347
7e8ed1fa25bd
lib-http: client: Improved request reference counting in connection code.
Stephan Bosch <stephan@dovecot.fi>
parents:
20346
diff
changeset
|
643 http_client_peer_trigger_request_handler(conn->peer); |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
644 } |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
645 |
22212
8cc50c161f4a
lib-http: client: Explicitly destroy the response payload timeout stream when the request is destroyed while receiving payload.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21874
diff
changeset
|
646 void http_client_connection_request_destroyed( |
8cc50c161f4a
lib-http: client: Explicitly destroy the response payload timeout stream when the request is destroyed while receiving payload.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21874
diff
changeset
|
647 struct http_client_connection *conn, struct http_client_request *req) |
8cc50c161f4a
lib-http: client: Explicitly destroy the response payload timeout stream when the request is destroyed while receiving payload.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21874
diff
changeset
|
648 { |
22213
f8d4ae988e7f
lib-http: client: When a request is destroyed prematurely during payload input, consider the payload stream destroyed and act accordingly.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
22212
diff
changeset
|
649 struct istream *payload; |
22212
8cc50c161f4a
lib-http: client: Explicitly destroy the response payload timeout stream when the request is destroyed while receiving payload.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21874
diff
changeset
|
650 |
8cc50c161f4a
lib-http: client: Explicitly destroy the response payload timeout stream when the request is destroyed while receiving payload.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21874
diff
changeset
|
651 i_assert(req->conn == conn); |
8cc50c161f4a
lib-http: client: Explicitly destroy the response payload timeout stream when the request is destroyed while receiving payload.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21874
diff
changeset
|
652 if (conn->pending_request != req) |
8cc50c161f4a
lib-http: client: Explicitly destroy the response payload timeout stream when the request is destroyed while receiving payload.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21874
diff
changeset
|
653 return; |
8cc50c161f4a
lib-http: client: Explicitly destroy the response payload timeout stream when the request is destroyed while receiving payload.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21874
diff
changeset
|
654 |
8cc50c161f4a
lib-http: client: Explicitly destroy the response payload timeout stream when the request is destroyed while receiving payload.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21874
diff
changeset
|
655 http_client_connection_debug(conn, |
8cc50c161f4a
lib-http: client: Explicitly destroy the response payload timeout stream when the request is destroyed while receiving payload.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21874
diff
changeset
|
656 "Pending request destroyed prematurely"); |
8cc50c161f4a
lib-http: client: Explicitly destroy the response payload timeout stream when the request is destroyed while receiving payload.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21874
diff
changeset
|
657 |
22213
f8d4ae988e7f
lib-http: client: When a request is destroyed prematurely during payload input, consider the payload stream destroyed and act accordingly.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
22212
diff
changeset
|
658 payload = conn->incoming_payload; |
f8d4ae988e7f
lib-http: client: When a request is destroyed prematurely during payload input, consider the payload stream destroyed and act accordingly.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
22212
diff
changeset
|
659 if (payload == NULL) { |
f8d4ae988e7f
lib-http: client: When a request is destroyed prematurely during payload input, consider the payload stream destroyed and act accordingly.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
22212
diff
changeset
|
660 /* payload already gone */ |
22212
8cc50c161f4a
lib-http: client: Explicitly destroy the response payload timeout stream when the request is destroyed while receiving payload.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21874
diff
changeset
|
661 return; |
22213
f8d4ae988e7f
lib-http: client: When a request is destroyed prematurely during payload input, consider the payload stream destroyed and act accordingly.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
22212
diff
changeset
|
662 } |
f8d4ae988e7f
lib-http: client: When a request is destroyed prematurely during payload input, consider the payload stream destroyed and act accordingly.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
22212
diff
changeset
|
663 |
f8d4ae988e7f
lib-http: client: When a request is destroyed prematurely during payload input, consider the payload stream destroyed and act accordingly.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
22212
diff
changeset
|
664 /* destroy the payload, so that the timeout istream is closed */ |
22212
8cc50c161f4a
lib-http: client: Explicitly destroy the response payload timeout stream when the request is destroyed while receiving payload.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21874
diff
changeset
|
665 i_stream_ref(payload); |
8cc50c161f4a
lib-http: client: Explicitly destroy the response payload timeout stream when the request is destroyed while receiving payload.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21874
diff
changeset
|
666 i_stream_destroy(&payload); |
22213
f8d4ae988e7f
lib-http: client: When a request is destroyed prematurely during payload input, consider the payload stream destroyed and act accordingly.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
22212
diff
changeset
|
667 |
f8d4ae988e7f
lib-http: client: When a request is destroyed prematurely during payload input, consider the payload stream destroyed and act accordingly.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
22212
diff
changeset
|
668 payload = conn->incoming_payload; |
f8d4ae988e7f
lib-http: client: When a request is destroyed prematurely during payload input, consider the payload stream destroyed and act accordingly.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
22212
diff
changeset
|
669 if (payload == NULL) { |
f8d4ae988e7f
lib-http: client: When a request is destroyed prematurely during payload input, consider the payload stream destroyed and act accordingly.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
22212
diff
changeset
|
670 /* not going to happen, but check for it anyway */ |
f8d4ae988e7f
lib-http: client: When a request is destroyed prematurely during payload input, consider the payload stream destroyed and act accordingly.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
22212
diff
changeset
|
671 return; |
f8d4ae988e7f
lib-http: client: When a request is destroyed prematurely during payload input, consider the payload stream destroyed and act accordingly.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
22212
diff
changeset
|
672 } |
f8d4ae988e7f
lib-http: client: When a request is destroyed prematurely during payload input, consider the payload stream destroyed and act accordingly.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
22212
diff
changeset
|
673 |
f8d4ae988e7f
lib-http: client: When a request is destroyed prematurely during payload input, consider the payload stream destroyed and act accordingly.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
22212
diff
changeset
|
674 /* the application still holds a reference to the payload stream, but it |
f8d4ae988e7f
lib-http: client: When a request is destroyed prematurely during payload input, consider the payload stream destroyed and act accordingly.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
22212
diff
changeset
|
675 is closed and we don't care about it anymore, so act as though it is |
f8d4ae988e7f
lib-http: client: When a request is destroyed prematurely during payload input, consider the payload stream destroyed and act accordingly.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
22212
diff
changeset
|
676 destroyed. */ |
f8d4ae988e7f
lib-http: client: When a request is destroyed prematurely during payload input, consider the payload stream destroyed and act accordingly.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
22212
diff
changeset
|
677 i_stream_remove_destroy_callback(payload, |
f8d4ae988e7f
lib-http: client: When a request is destroyed prematurely during payload input, consider the payload stream destroyed and act accordingly.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
22212
diff
changeset
|
678 http_client_payload_destroyed); |
f8d4ae988e7f
lib-http: client: When a request is destroyed prematurely during payload input, consider the payload stream destroyed and act accordingly.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
22212
diff
changeset
|
679 http_client_payload_destroyed(req); |
22212
8cc50c161f4a
lib-http: client: Explicitly destroy the response payload timeout stream when the request is destroyed while receiving payload.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21874
diff
changeset
|
680 } |
8cc50c161f4a
lib-http: client: Explicitly destroy the response payload timeout stream when the request is destroyed while receiving payload.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21874
diff
changeset
|
681 |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
682 static bool |
20347
7e8ed1fa25bd
lib-http: client: Improved request reference counting in connection code.
Stephan Bosch <stephan@dovecot.fi>
parents:
20346
diff
changeset
|
683 http_client_connection_return_response( |
7e8ed1fa25bd
lib-http: client: Improved request reference counting in connection code.
Stephan Bosch <stephan@dovecot.fi>
parents:
20346
diff
changeset
|
684 struct http_client_connection *conn, |
7e8ed1fa25bd
lib-http: client: Improved request reference counting in connection code.
Stephan Bosch <stephan@dovecot.fi>
parents:
20346
diff
changeset
|
685 struct http_client_request *req, |
19816
e2f9c117aef7
lib-http: http_client_connection_unref() now always sets *conn=NULL
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19727
diff
changeset
|
686 struct http_response *response) |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
687 { |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
688 struct istream *payload; |
21424
e94ac3f36692
lib-http: client: Keep connection reference throughout http_client_connection_return_response().
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21390
diff
changeset
|
689 bool retrying; |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
690 |
17876
ecb0ba0ce02f
lib-http: client: Fixed problem occuring when a nested ioloop was run inside a request callback using the same client.
Stephan Bosch <stephan@rename-it.nl>
parents:
17857
diff
changeset
|
691 i_assert(!conn->in_req_callback); |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
692 i_assert(conn->incoming_payload == NULL); |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
693 i_assert(conn->pending_request == NULL); |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
694 |
21424
e94ac3f36692
lib-http: client: Keep connection reference throughout http_client_connection_return_response().
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21390
diff
changeset
|
695 http_client_connection_ref(conn); |
21425
70083e131e22
lib-http: client: Make sure req->conn is only not NULL when that connection holds a reference to that request.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21424
diff
changeset
|
696 http_client_connection_ref_request(conn, req); |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
697 req->state = HTTP_REQUEST_STATE_GOT_RESPONSE; |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
698 |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
699 if (response->payload != NULL) { |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
700 /* wrap the stream to capture the destroy event without destroying the |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
701 actual payload stream. */ |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
702 conn->incoming_payload = response->payload = |
17191
790afcf05f0d
lib-http: Wrap response payload istream into a istream-timeout.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
703 i_stream_create_timeout(response->payload, |
20584
6ff9cfbbdf4c
lib-http: Support per-request timeout and max_attempts
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20473
diff
changeset
|
704 req->attempt_timeout_msecs); |
16236
81d87e43e167
istream API change: Added support for multiple destroy callbacks.
Timo Sirainen <tss@iki.fi>
parents:
16218
diff
changeset
|
705 i_stream_add_destroy_callback(response->payload, |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
706 http_client_payload_destroyed, |
16005
d3e3edf8f7eb
lib-http: Fixed hangs with urgent requests.
Timo Sirainen <tss@iki.fi>
parents:
16001
diff
changeset
|
707 req); |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
708 /* the callback may add its own I/O, so we need to remove |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
709 our one before calling it */ |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
710 io_remove(&conn->conn.io); |
16571
9fd54d123e22
lib-http: Remove request timeout from being used during payload read.
Timo Sirainen <tss@iki.fi>
parents:
16569
diff
changeset
|
711 /* we've received the request itself, and we can't reset the |
9fd54d123e22
lib-http: Remove request timeout from being used during payload read.
Timo Sirainen <tss@iki.fi>
parents:
16569
diff
changeset
|
712 timeout during the payload reading. */ |
18969
a08e79a3707f
lib-http: client: Fixed handling of request timeout.
Stephan Bosch <stephan@rename-it.nl>
parents:
18494
diff
changeset
|
713 http_client_connection_stop_request_timeout(conn); |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
714 } |
17876
ecb0ba0ce02f
lib-http: client: Fixed problem occuring when a nested ioloop was run inside a request callback using the same client.
Stephan Bosch <stephan@rename-it.nl>
parents:
17857
diff
changeset
|
715 |
ecb0ba0ce02f
lib-http: client: Fixed problem occuring when a nested ioloop was run inside a request callback using the same client.
Stephan Bosch <stephan@rename-it.nl>
parents:
17857
diff
changeset
|
716 conn->in_req_callback = TRUE; |
16015
5606f1a6cbc6
lib-http: Don't crash if request callback manages to get the connection destroyed.
Timo Sirainen <tss@iki.fi>
parents:
16013
diff
changeset
|
717 retrying = !http_client_request_callback(req, response); |
21424
e94ac3f36692
lib-http: client: Keep connection reference throughout http_client_connection_return_response().
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21390
diff
changeset
|
718 if (conn->disconnected) { |
e94ac3f36692
lib-http: client: Keep connection reference throughout http_client_connection_return_response().
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21390
diff
changeset
|
719 /* the callback managed to get this connection disconnected */ |
16015
5606f1a6cbc6
lib-http: Don't crash if request callback manages to get the connection destroyed.
Timo Sirainen <tss@iki.fi>
parents:
16013
diff
changeset
|
720 if (!retrying) |
19817
fa23955f6028
lib-http: http_client_request_unref() now always sets *req=NULL
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19816
diff
changeset
|
721 http_client_request_finish(req); |
21425
70083e131e22
lib-http: client: Make sure req->conn is only not NULL when that connection holds a reference to that request.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21424
diff
changeset
|
722 http_client_connection_unref_request(conn, &req); |
21424
e94ac3f36692
lib-http: client: Keep connection reference throughout http_client_connection_return_response().
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21390
diff
changeset
|
723 http_client_connection_unref(&conn); |
16015
5606f1a6cbc6
lib-http: Don't crash if request callback manages to get the connection destroyed.
Timo Sirainen <tss@iki.fi>
parents:
16013
diff
changeset
|
724 return FALSE; |
5606f1a6cbc6
lib-http: Don't crash if request callback manages to get the connection destroyed.
Timo Sirainen <tss@iki.fi>
parents:
16013
diff
changeset
|
725 } |
17941
871a5b807ad0
lib-http: client: Fixed segfault caused by earlier change.
Stephan Bosch <stephan@rename-it.nl>
parents:
17882
diff
changeset
|
726 conn->in_req_callback = FALSE; |
16015
5606f1a6cbc6
lib-http: Don't crash if request callback manages to get the connection destroyed.
Timo Sirainen <tss@iki.fi>
parents:
16013
diff
changeset
|
727 |
5606f1a6cbc6
lib-http: Don't crash if request callback manages to get the connection destroyed.
Timo Sirainen <tss@iki.fi>
parents:
16013
diff
changeset
|
728 if (retrying) { |
16013
59572bce44fe
lib-http: Callback can now request a retry with http_client_request_try_retry()
Timo Sirainen <tss@iki.fi>
parents:
16010
diff
changeset
|
729 /* retrying, don't destroy the request */ |
59572bce44fe
lib-http: Callback can now request a retry with http_client_request_try_retry()
Timo Sirainen <tss@iki.fi>
parents:
16010
diff
changeset
|
730 if (response->payload != NULL) { |
16236
81d87e43e167
istream API change: Added support for multiple destroy callbacks.
Timo Sirainen <tss@iki.fi>
parents:
16218
diff
changeset
|
731 i_stream_remove_destroy_callback(conn->incoming_payload, |
81d87e43e167
istream API change: Added support for multiple destroy callbacks.
Timo Sirainen <tss@iki.fi>
parents:
16218
diff
changeset
|
732 http_client_payload_destroyed); |
16013
59572bce44fe
lib-http: Callback can now request a retry with http_client_request_try_retry()
Timo Sirainen <tss@iki.fi>
parents:
16010
diff
changeset
|
733 i_stream_unref(&conn->incoming_payload); |
17192
a1c153c70bb9
Use io_add_istream() wherever possible.
Timo Sirainen <tss@iki.fi>
parents:
17191
diff
changeset
|
734 conn->conn.io = io_add_istream(conn->conn.input, |
16013
59572bce44fe
lib-http: Callback can now request a retry with http_client_request_try_retry()
Timo Sirainen <tss@iki.fi>
parents:
16010
diff
changeset
|
735 http_client_connection_input, |
59572bce44fe
lib-http: Callback can now request a retry with http_client_request_try_retry()
Timo Sirainen <tss@iki.fi>
parents:
16010
diff
changeset
|
736 &conn->conn); |
59572bce44fe
lib-http: Callback can now request a retry with http_client_request_try_retry()
Timo Sirainen <tss@iki.fi>
parents:
16010
diff
changeset
|
737 } |
21425
70083e131e22
lib-http: client: Make sure req->conn is only not NULL when that connection holds a reference to that request.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21424
diff
changeset
|
738 http_client_connection_unref_request(conn, &req); |
21424
e94ac3f36692
lib-http: client: Keep connection reference throughout http_client_connection_return_response().
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21390
diff
changeset
|
739 return http_client_connection_unref(&conn); |
16013
59572bce44fe
lib-http: Callback can now request a retry with http_client_request_try_retry()
Timo Sirainen <tss@iki.fi>
parents:
16010
diff
changeset
|
740 } |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
741 |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
742 if (response->payload != NULL) { |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
743 req->state = HTTP_REQUEST_STATE_PAYLOAD_IN; |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
744 payload = response->payload; |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
745 response->payload = NULL; |
20347
7e8ed1fa25bd
lib-http: client: Improved request reference counting in connection code.
Stephan Bosch <stephan@dovecot.fi>
parents:
20346
diff
changeset
|
746 |
7e8ed1fa25bd
lib-http: client: Improved request reference counting in connection code.
Stephan Bosch <stephan@dovecot.fi>
parents:
20346
diff
changeset
|
747 /* maintain request reference while payload is pending */ |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
748 conn->pending_request = req; |
17881
4f175c27bea5
lib-http: client: Added support for absolute request timeout.
Stephan Bosch <stephan@rename-it.nl>
parents:
17876
diff
changeset
|
749 |
4f175c27bea5
lib-http: client: Added support for absolute request timeout.
Stephan Bosch <stephan@rename-it.nl>
parents:
17876
diff
changeset
|
750 /* request is dereferenced in payload destroy callback */ |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
751 i_stream_unref(&payload); |
17881
4f175c27bea5
lib-http: client: Added support for absolute request timeout.
Stephan Bosch <stephan@rename-it.nl>
parents:
17876
diff
changeset
|
752 |
19235
77486e114423
lib-http: Avoid crashes when server is already disconnected.
Timo Sirainen <tss@iki.fi>
parents:
19234
diff
changeset
|
753 if (conn->to_input != NULL && conn->conn.input != NULL) { |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
754 /* already finished reading the payload */ |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
755 http_client_payload_finished(conn); |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
756 } |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
757 } else { |
19817
fa23955f6028
lib-http: http_client_request_unref() now always sets *req=NULL
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19816
diff
changeset
|
758 http_client_request_finish(req); |
21425
70083e131e22
lib-http: client: Make sure req->conn is only not NULL when that connection holds a reference to that request.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21424
diff
changeset
|
759 http_client_connection_unref_request(conn, &req); |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
760 } |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
761 |
19235
77486e114423
lib-http: Avoid crashes when server is already disconnected.
Timo Sirainen <tss@iki.fi>
parents:
19234
diff
changeset
|
762 if (conn->incoming_payload == NULL && conn->conn.input != NULL) { |
16855
c3884a6acde6
lib-http: Added support for creating CONNECT tunnels through HTTP.
Stephan Bosch <stephan@rename-it.nl>
parents:
16852
diff
changeset
|
763 i_assert(conn->conn.io != NULL || |
c3884a6acde6
lib-http: Added support for creating CONNECT tunnels through HTTP.
Stephan Bosch <stephan@rename-it.nl>
parents:
16852
diff
changeset
|
764 conn->peer->addr.type == HTTP_CLIENT_PEER_ADDR_RAW); |
21424
e94ac3f36692
lib-http: client: Keep connection reference throughout http_client_connection_return_response().
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21390
diff
changeset
|
765 return http_client_connection_unref(&conn); |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
766 } |
19234
44dd7e81a38b
lib-http: Disconnection from HTTP server could have caused accessing already freed memory.
Timo Sirainen <tss@iki.fi>
parents:
19039
diff
changeset
|
767 http_client_connection_unref(&conn); |
21424
e94ac3f36692
lib-http: client: Keep connection reference throughout http_client_connection_return_response().
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21390
diff
changeset
|
768 return FALSE; |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
769 } |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
770 |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
771 static void http_client_connection_input(struct connection *_conn) |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
772 { |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
773 struct http_client_connection *conn = |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
774 (struct http_client_connection *)_conn; |
16740
adb4d013073d
lib-http: Adjusted response and request parsers to accept a request/response object to fill with data, rather than have it return one.
Stephan Bosch <stephan@rename-it.nl>
parents:
16739
diff
changeset
|
775 struct http_response response; |
18001
cffa8349f167
lib-http: client: Fixed handling of requests aborted while still sending payload to server.
Stephan Bosch <stephan@rename-it.nl>
parents:
17999
diff
changeset
|
776 struct http_client_request *const *reqs; |
19817
fa23955f6028
lib-http: http_client_request_unref() now always sets *req=NULL
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19816
diff
changeset
|
777 struct http_client_request *req = NULL, *req_ref; |
18001
cffa8349f167
lib-http: client: Fixed handling of requests aborted while still sending payload to server.
Stephan Bosch <stephan@rename-it.nl>
parents:
17999
diff
changeset
|
778 enum http_response_payload_type payload_type; |
cffa8349f167
lib-http: client: Fixed handling of requests aborted while still sending payload to server.
Stephan Bosch <stephan@rename-it.nl>
parents:
17999
diff
changeset
|
779 unsigned int count; |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
780 int finished = 0, ret; |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
781 const char *error; |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
782 |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
783 i_assert(conn->incoming_payload == NULL); |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
784 |
19524
3df66d89a87a
lib-http: Add more timing information to debug logs when HTTP connections get closed.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19461
diff
changeset
|
785 _conn->last_input = ioloop_time; |
3df66d89a87a
lib-http: Add more timing information to debug logs when HTTP connections get closed.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19461
diff
changeset
|
786 |
17970
7d3325713356
lib-http: client: Connection erroneously indicated that it was ready while SSL handshake was not yet completed.
Stephan Bosch <stephan@rename-it.nl>
parents:
17968
diff
changeset
|
787 if (conn->ssl_iostream != NULL && |
7d3325713356
lib-http: client: Connection erroneously indicated that it was ready while SSL handshake was not yet completed.
Stephan Bosch <stephan@rename-it.nl>
parents:
17968
diff
changeset
|
788 !ssl_iostream_is_handshaked(conn->ssl_iostream)) { |
7d3325713356
lib-http: client: Connection erroneously indicated that it was ready while SSL handshake was not yet completed.
Stephan Bosch <stephan@rename-it.nl>
parents:
17968
diff
changeset
|
789 /* finish SSL negotiation by reading from input stream */ |
20828
d7bed2a85e99
global: Make sure i_stream_read() calls handle 0 and -2 return values correctly.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20742
diff
changeset
|
790 while ((ret=i_stream_read(conn->conn.input)) > 0 || ret == -2) { |
17970
7d3325713356
lib-http: client: Connection erroneously indicated that it was ready while SSL handshake was not yet completed.
Stephan Bosch <stephan@rename-it.nl>
parents:
17968
diff
changeset
|
791 if (ssl_iostream_is_handshaked(conn->ssl_iostream)) |
7d3325713356
lib-http: client: Connection erroneously indicated that it was ready while SSL handshake was not yet completed.
Stephan Bosch <stephan@rename-it.nl>
parents:
17968
diff
changeset
|
792 break; |
7d3325713356
lib-http: client: Connection erroneously indicated that it was ready while SSL handshake was not yet completed.
Stephan Bosch <stephan@rename-it.nl>
parents:
17968
diff
changeset
|
793 } |
7d3325713356
lib-http: client: Connection erroneously indicated that it was ready while SSL handshake was not yet completed.
Stephan Bosch <stephan@rename-it.nl>
parents:
17968
diff
changeset
|
794 if (ret < 0) { |
7d3325713356
lib-http: client: Connection erroneously indicated that it was ready while SSL handshake was not yet completed.
Stephan Bosch <stephan@rename-it.nl>
parents:
17968
diff
changeset
|
795 int stream_errno = conn->conn.input->stream_errno; |
7d3325713356
lib-http: client: Connection erroneously indicated that it was ready while SSL handshake was not yet completed.
Stephan Bosch <stephan@rename-it.nl>
parents:
17968
diff
changeset
|
796 |
7d3325713356
lib-http: client: Connection erroneously indicated that it was ready while SSL handshake was not yet completed.
Stephan Bosch <stephan@rename-it.nl>
parents:
17968
diff
changeset
|
797 /* failed somehow */ |
7d3325713356
lib-http: client: Connection erroneously indicated that it was ready while SSL handshake was not yet completed.
Stephan Bosch <stephan@rename-it.nl>
parents:
17968
diff
changeset
|
798 i_assert(ret != -2); |
7d3325713356
lib-http: client: Connection erroneously indicated that it was ready while SSL handshake was not yet completed.
Stephan Bosch <stephan@rename-it.nl>
parents:
17968
diff
changeset
|
799 error = t_strdup_printf( |
7d3325713356
lib-http: client: Connection erroneously indicated that it was ready while SSL handshake was not yet completed.
Stephan Bosch <stephan@rename-it.nl>
parents:
17968
diff
changeset
|
800 "SSL handshaking with %s failed: " |
7d3325713356
lib-http: client: Connection erroneously indicated that it was ready while SSL handshake was not yet completed.
Stephan Bosch <stephan@rename-it.nl>
parents:
17968
diff
changeset
|
801 "read(%s) failed: %s", |
7d3325713356
lib-http: client: Connection erroneously indicated that it was ready while SSL handshake was not yet completed.
Stephan Bosch <stephan@rename-it.nl>
parents:
17968
diff
changeset
|
802 _conn->name, |
7d3325713356
lib-http: client: Connection erroneously indicated that it was ready while SSL handshake was not yet completed.
Stephan Bosch <stephan@rename-it.nl>
parents:
17968
diff
changeset
|
803 i_stream_get_name(conn->conn.input), |
7d3325713356
lib-http: client: Connection erroneously indicated that it was ready while SSL handshake was not yet completed.
Stephan Bosch <stephan@rename-it.nl>
parents:
17968
diff
changeset
|
804 stream_errno != 0 ? |
7d3325713356
lib-http: client: Connection erroneously indicated that it was ready while SSL handshake was not yet completed.
Stephan Bosch <stephan@rename-it.nl>
parents:
17968
diff
changeset
|
805 i_stream_get_error(conn->conn.input) : "EOF"); |
7d3325713356
lib-http: client: Connection erroneously indicated that it was ready while SSL handshake was not yet completed.
Stephan Bosch <stephan@rename-it.nl>
parents:
17968
diff
changeset
|
806 http_client_peer_connection_failure(conn->peer, error); |
7d3325713356
lib-http: client: Connection erroneously indicated that it was ready while SSL handshake was not yet completed.
Stephan Bosch <stephan@rename-it.nl>
parents:
17968
diff
changeset
|
807 http_client_connection_debug(conn, "%s", error); |
7d3325713356
lib-http: client: Connection erroneously indicated that it was ready while SSL handshake was not yet completed.
Stephan Bosch <stephan@rename-it.nl>
parents:
17968
diff
changeset
|
808 http_client_connection_close(&conn); |
7d3325713356
lib-http: client: Connection erroneously indicated that it was ready while SSL handshake was not yet completed.
Stephan Bosch <stephan@rename-it.nl>
parents:
17968
diff
changeset
|
809 return; |
7d3325713356
lib-http: client: Connection erroneously indicated that it was ready while SSL handshake was not yet completed.
Stephan Bosch <stephan@rename-it.nl>
parents:
17968
diff
changeset
|
810 } |
7d3325713356
lib-http: client: Connection erroneously indicated that it was ready while SSL handshake was not yet completed.
Stephan Bosch <stephan@rename-it.nl>
parents:
17968
diff
changeset
|
811 |
7d3325713356
lib-http: client: Connection erroneously indicated that it was ready while SSL handshake was not yet completed.
Stephan Bosch <stephan@rename-it.nl>
parents:
17968
diff
changeset
|
812 if (!ssl_iostream_is_handshaked(conn->ssl_iostream)) { |
7d3325713356
lib-http: client: Connection erroneously indicated that it was ready while SSL handshake was not yet completed.
Stephan Bosch <stephan@rename-it.nl>
parents:
17968
diff
changeset
|
813 /* not finished */ |
7d3325713356
lib-http: client: Connection erroneously indicated that it was ready while SSL handshake was not yet completed.
Stephan Bosch <stephan@rename-it.nl>
parents:
17968
diff
changeset
|
814 i_assert(ret == 0); |
7d3325713356
lib-http: client: Connection erroneously indicated that it was ready while SSL handshake was not yet completed.
Stephan Bosch <stephan@rename-it.nl>
parents:
17968
diff
changeset
|
815 return; |
7d3325713356
lib-http: client: Connection erroneously indicated that it was ready while SSL handshake was not yet completed.
Stephan Bosch <stephan@rename-it.nl>
parents:
17968
diff
changeset
|
816 } |
7d3325713356
lib-http: client: Connection erroneously indicated that it was ready while SSL handshake was not yet completed.
Stephan Bosch <stephan@rename-it.nl>
parents:
17968
diff
changeset
|
817 |
7d3325713356
lib-http: client: Connection erroneously indicated that it was ready while SSL handshake was not yet completed.
Stephan Bosch <stephan@rename-it.nl>
parents:
17968
diff
changeset
|
818 /* ready for first request */ |
7d3325713356
lib-http: client: Connection erroneously indicated that it was ready while SSL handshake was not yet completed.
Stephan Bosch <stephan@rename-it.nl>
parents:
17968
diff
changeset
|
819 http_client_connection_ready(conn); |
7d3325713356
lib-http: client: Connection erroneously indicated that it was ready while SSL handshake was not yet completed.
Stephan Bosch <stephan@rename-it.nl>
parents:
17968
diff
changeset
|
820 } |
7d3325713356
lib-http: client: Connection erroneously indicated that it was ready while SSL handshake was not yet completed.
Stephan Bosch <stephan@rename-it.nl>
parents:
17968
diff
changeset
|
821 |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
822 if (conn->to_input != NULL) { |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
823 /* We came here from a timeout added by |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
824 http_client_payload_destroyed(). The IO couldn't be added |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
825 back immediately in there, because the HTTP API user may |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
826 still have had its own IO pointed to the same fd. It should |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
827 be removed by now, so we can add it back. */ |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
828 http_client_payload_finished(conn); |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
829 finished++; |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
830 } |
18969
a08e79a3707f
lib-http: client: Fixed handling of request timeout.
Stephan Bosch <stephan@rename-it.nl>
parents:
18494
diff
changeset
|
831 |
a08e79a3707f
lib-http: client: Fixed handling of request timeout.
Stephan Bosch <stephan@rename-it.nl>
parents:
18494
diff
changeset
|
832 /* we've seen activity from the server; reset request timeout */ |
a08e79a3707f
lib-http: client: Fixed handling of request timeout.
Stephan Bosch <stephan@rename-it.nl>
parents:
18494
diff
changeset
|
833 http_client_connection_reset_request_timeout(conn); |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
834 |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
835 /* get first waiting request */ |
18001
cffa8349f167
lib-http: client: Fixed handling of requests aborted while still sending payload to server.
Stephan Bosch <stephan@rename-it.nl>
parents:
17999
diff
changeset
|
836 reqs = array_get(&conn->request_wait_list, &count); |
cffa8349f167
lib-http: client: Fixed handling of requests aborted while still sending payload to server.
Stephan Bosch <stephan@rename-it.nl>
parents:
17999
diff
changeset
|
837 if (count > 0) { |
cffa8349f167
lib-http: client: Fixed handling of requests aborted while still sending payload to server.
Stephan Bosch <stephan@rename-it.nl>
parents:
17999
diff
changeset
|
838 req = reqs[0]; |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
839 |
16855
c3884a6acde6
lib-http: Added support for creating CONNECT tunnels through HTTP.
Stephan Bosch <stephan@rename-it.nl>
parents:
16852
diff
changeset
|
840 /* determine whether to expect a response payload */ |
c3884a6acde6
lib-http: Added support for creating CONNECT tunnels through HTTP.
Stephan Bosch <stephan@rename-it.nl>
parents:
16852
diff
changeset
|
841 payload_type = http_client_request_get_payload_type(req); |
c3884a6acde6
lib-http: Added support for creating CONNECT tunnels through HTTP.
Stephan Bosch <stephan@rename-it.nl>
parents:
16852
diff
changeset
|
842 } else { |
c3884a6acde6
lib-http: Added support for creating CONNECT tunnels through HTTP.
Stephan Bosch <stephan@rename-it.nl>
parents:
16852
diff
changeset
|
843 req = NULL; |
c3884a6acde6
lib-http: Added support for creating CONNECT tunnels through HTTP.
Stephan Bosch <stephan@rename-it.nl>
parents:
16852
diff
changeset
|
844 payload_type = HTTP_RESPONSE_PAYLOAD_TYPE_ALLOWED; |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
845 } |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
846 |
18001
cffa8349f167
lib-http: client: Fixed handling of requests aborted while still sending payload to server.
Stephan Bosch <stephan@rename-it.nl>
parents:
17999
diff
changeset
|
847 /* drop connection with broken output if last possible input was |
cffa8349f167
lib-http: client: Fixed handling of requests aborted while still sending payload to server.
Stephan Bosch <stephan@rename-it.nl>
parents:
17999
diff
changeset
|
848 received */ |
cffa8349f167
lib-http: client: Fixed handling of requests aborted while still sending payload to server.
Stephan Bosch <stephan@rename-it.nl>
parents:
17999
diff
changeset
|
849 if (conn->output_broken && (count == 0 || |
cffa8349f167
lib-http: client: Fixed handling of requests aborted while still sending payload to server.
Stephan Bosch <stephan@rename-it.nl>
parents:
17999
diff
changeset
|
850 (count == 1 && req->state == HTTP_REQUEST_STATE_ABORTED))) { |
cffa8349f167
lib-http: client: Fixed handling of requests aborted while still sending payload to server.
Stephan Bosch <stephan@rename-it.nl>
parents:
17999
diff
changeset
|
851 http_client_connection_server_close(&conn); |
cffa8349f167
lib-http: client: Fixed handling of requests aborted while still sending payload to server.
Stephan Bosch <stephan@rename-it.nl>
parents:
17999
diff
changeset
|
852 return; |
cffa8349f167
lib-http: client: Fixed handling of requests aborted while still sending payload to server.
Stephan Bosch <stephan@rename-it.nl>
parents:
17999
diff
changeset
|
853 } |
cffa8349f167
lib-http: client: Fixed handling of requests aborted while still sending payload to server.
Stephan Bosch <stephan@rename-it.nl>
parents:
17999
diff
changeset
|
854 |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
855 while ((ret=http_response_parse_next |
16855
c3884a6acde6
lib-http: Added support for creating CONNECT tunnels through HTTP.
Stephan Bosch <stephan@rename-it.nl>
parents:
16852
diff
changeset
|
856 (conn->http_parser, payload_type, &response, &error)) > 0) { |
18002
4dc3c0cacd25
lib-http: client: Handle situation in which server sends response before request payload is fully sent.
Stephan Bosch <stephan@rename-it.nl>
parents:
18001
diff
changeset
|
857 bool aborted, early = FALSE; |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
858 |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
859 if (req == NULL) { |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
860 /* server sent response without any requests in the wait list */ |
19033
a8e01e385e90
lib-http: client: Added proper handling of 408 response status.
Stephan Bosch <stephan@rename-it.nl>
parents:
18969
diff
changeset
|
861 if (response.status == 408) { |
a8e01e385e90
lib-http: client: Added proper handling of 408 response status.
Stephan Bosch <stephan@rename-it.nl>
parents:
18969
diff
changeset
|
862 http_client_connection_debug(conn, |
a8e01e385e90
lib-http: client: Added proper handling of 408 response status.
Stephan Bosch <stephan@rename-it.nl>
parents:
18969
diff
changeset
|
863 "Server explicitly closed connection: 408 %s", |
a8e01e385e90
lib-http: client: Added proper handling of 408 response status.
Stephan Bosch <stephan@rename-it.nl>
parents:
18969
diff
changeset
|
864 response.reason); |
a8e01e385e90
lib-http: client: Added proper handling of 408 response status.
Stephan Bosch <stephan@rename-it.nl>
parents:
18969
diff
changeset
|
865 } else { |
a8e01e385e90
lib-http: client: Added proper handling of 408 response status.
Stephan Bosch <stephan@rename-it.nl>
parents:
18969
diff
changeset
|
866 http_client_connection_debug(conn, |
a8e01e385e90
lib-http: client: Added proper handling of 408 response status.
Stephan Bosch <stephan@rename-it.nl>
parents:
18969
diff
changeset
|
867 "Got unexpected input from server: %u %s", |
a8e01e385e90
lib-http: client: Added proper handling of 408 response status.
Stephan Bosch <stephan@rename-it.nl>
parents:
18969
diff
changeset
|
868 response.status, response.reason); |
a8e01e385e90
lib-http: client: Added proper handling of 408 response status.
Stephan Bosch <stephan@rename-it.nl>
parents:
18969
diff
changeset
|
869 } |
17968
c5f81685571f
lib-http: client: Fixed handling of connection timeouts.
Stephan Bosch <stephan@rename-it.nl>
parents:
17941
diff
changeset
|
870 http_client_connection_close(&conn); |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
871 return; |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
872 } |
17625
b162e39909d7
lib-http: Debug log now includes where HTTP requests spent their time on.
Timo Sirainen <tss@iki.fi>
parents:
17610
diff
changeset
|
873 req->response_time = ioloop_timeval; |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
874 |
15460
7a4d8cd0e079
lib-http: Added support for chunked input/output streams and some bugfixes.
Stephan Bosch <stephan@rename-it.nl>
parents:
15440
diff
changeset
|
875 /* Got some response; cancel response timeout */ |
7a4d8cd0e079
lib-http: Added support for chunked input/output streams and some bugfixes.
Stephan Bosch <stephan@rename-it.nl>
parents:
15440
diff
changeset
|
876 if (conn->to_response != NULL) |
7a4d8cd0e079
lib-http: Added support for chunked input/output streams and some bugfixes.
Stephan Bosch <stephan@rename-it.nl>
parents:
15440
diff
changeset
|
877 timeout_remove(&conn->to_response); |
7a4d8cd0e079
lib-http: Added support for chunked input/output streams and some bugfixes.
Stephan Bosch <stephan@rename-it.nl>
parents:
15440
diff
changeset
|
878 |
17549
9511372c7c18
lib-http: Updated comments to RFC7230/RFC7231.
Stephan Bosch <stephan@rename-it.nl>
parents:
17521
diff
changeset
|
879 /* RFC 7231, Section 6.2: |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
880 |
17549
9511372c7c18
lib-http: Updated comments to RFC7230/RFC7231.
Stephan Bosch <stephan@rename-it.nl>
parents:
17521
diff
changeset
|
881 A client MUST be able to parse one or more 1xx responses received |
9511372c7c18
lib-http: Updated comments to RFC7230/RFC7231.
Stephan Bosch <stephan@rename-it.nl>
parents:
17521
diff
changeset
|
882 prior to a final response, even if the client does not expect one. A |
9511372c7c18
lib-http: Updated comments to RFC7230/RFC7231.
Stephan Bosch <stephan@rename-it.nl>
parents:
17521
diff
changeset
|
883 user agent MAY ignore unexpected 1xx responses. |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
884 */ |
16740
adb4d013073d
lib-http: Adjusted response and request parsers to accept a request/response object to fill with data, rather than have it return one.
Stephan Bosch <stephan@rename-it.nl>
parents:
16739
diff
changeset
|
885 if (req->payload_sync && response.status == 100) { |
19727
8f72e4f0ed5d
lib-http: client: Fixed pipelining bug: client sometimes sent new request while still waiting for 100-continue.
Stephan Bosch <stephan@rename-it.nl>
parents:
19726
diff
changeset
|
886 if (req->payload_sync_continue) { |
16218
3647c414c67d
lib-http: Fixed receiving 100-continue reply after we already timed out waiting for it.
Timo Sirainen <tss@iki.fi>
parents:
16161
diff
changeset
|
887 http_client_connection_debug(conn, |
3647c414c67d
lib-http: Fixed receiving 100-continue reply after we already timed out waiting for it.
Timo Sirainen <tss@iki.fi>
parents:
16161
diff
changeset
|
888 "Got 100-continue response after timeout"); |
16730
7b775a06c38f
lib-http: http-client: Fixed pipelining when payload synchronizatio (100-continue) is used.
Stephan Bosch <stephan@rename-it.nl>
parents:
16640
diff
changeset
|
889 continue; |
16218
3647c414c67d
lib-http: Fixed receiving 100-continue reply after we already timed out waiting for it.
Timo Sirainen <tss@iki.fi>
parents:
16161
diff
changeset
|
890 } |
18001
cffa8349f167
lib-http: client: Fixed handling of requests aborted while still sending payload to server.
Stephan Bosch <stephan@rename-it.nl>
parents:
17999
diff
changeset
|
891 |
16453
bcf93c30a500
lib-http: After peer has received 100 response, don't add ambiguity timeout anymore.
Timo Sirainen <tss@iki.fi>
parents:
16452
diff
changeset
|
892 conn->peer->no_payload_sync = FALSE; |
bcf93c30a500
lib-http: After peer has received 100 response, don't add ambiguity timeout anymore.
Timo Sirainen <tss@iki.fi>
parents:
16452
diff
changeset
|
893 conn->peer->seen_100_response = TRUE; |
19727
8f72e4f0ed5d
lib-http: client: Fixed pipelining bug: client sometimes sent new request while still waiting for 100-continue.
Stephan Bosch <stephan@rename-it.nl>
parents:
19726
diff
changeset
|
894 req->payload_sync_continue = TRUE; |
18001
cffa8349f167
lib-http: client: Fixed handling of requests aborted while still sending payload to server.
Stephan Bosch <stephan@rename-it.nl>
parents:
17999
diff
changeset
|
895 |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
896 http_client_connection_debug(conn, |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
897 "Got expected 100-continue response"); |
18001
cffa8349f167
lib-http: client: Fixed handling of requests aborted while still sending payload to server.
Stephan Bosch <stephan@rename-it.nl>
parents:
17999
diff
changeset
|
898 |
cffa8349f167
lib-http: client: Fixed handling of requests aborted while still sending payload to server.
Stephan Bosch <stephan@rename-it.nl>
parents:
17999
diff
changeset
|
899 if (req->state == HTTP_REQUEST_STATE_ABORTED) { |
cffa8349f167
lib-http: client: Fixed handling of requests aborted while still sending payload to server.
Stephan Bosch <stephan@rename-it.nl>
parents:
17999
diff
changeset
|
900 http_client_connection_debug(conn, |
cffa8349f167
lib-http: client: Fixed handling of requests aborted while still sending payload to server.
Stephan Bosch <stephan@rename-it.nl>
parents:
17999
diff
changeset
|
901 "Request aborted before sending payload was complete."); |
cffa8349f167
lib-http: client: Fixed handling of requests aborted while still sending payload to server.
Stephan Bosch <stephan@rename-it.nl>
parents:
17999
diff
changeset
|
902 http_client_connection_close(&conn); |
cffa8349f167
lib-http: client: Fixed handling of requests aborted while still sending payload to server.
Stephan Bosch <stephan@rename-it.nl>
parents:
17999
diff
changeset
|
903 return; |
cffa8349f167
lib-http: client: Fixed handling of requests aborted while still sending payload to server.
Stephan Bosch <stephan@rename-it.nl>
parents:
17999
diff
changeset
|
904 } |
cffa8349f167
lib-http: client: Fixed handling of requests aborted while still sending payload to server.
Stephan Bosch <stephan@rename-it.nl>
parents:
17999
diff
changeset
|
905 |
19961
3f6a74b9ce54
lib-http: client: Fixed request timeout handling during pipelining.
Stephan Bosch <stephan@rename-it.nl>
parents:
19937
diff
changeset
|
906 if (http_client_request_send_more(req, FALSE, &error) < 0) { |
21333
f7bc77720fe5
lib-http: client: Consolidated connection loss handling into a single function.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21108
diff
changeset
|
907 http_client_connection_lost(&conn, |
15999
f89ebdc1625d
lib-http: If we get disconnected, say exactly what the error was.
Timo Sirainen <tss@iki.fi>
parents:
15879
diff
changeset
|
908 t_strdup_printf("Failed to send request: %s", error)); |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
909 } |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
910 return; |
16740
adb4d013073d
lib-http: Adjusted response and request parsers to accept a request/response object to fill with data, rather than have it return one.
Stephan Bosch <stephan@rename-it.nl>
parents:
16739
diff
changeset
|
911 } else if (response.status / 100 == 1) { |
18001
cffa8349f167
lib-http: client: Fixed handling of requests aborted while still sending payload to server.
Stephan Bosch <stephan@rename-it.nl>
parents:
17999
diff
changeset
|
912 /* ignore other 1xx for now */ |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
913 http_client_connection_debug(conn, |
16740
adb4d013073d
lib-http: Adjusted response and request parsers to accept a request/response object to fill with data, rather than have it return one.
Stephan Bosch <stephan@rename-it.nl>
parents:
16739
diff
changeset
|
914 "Got unexpected %u response; ignoring", response.status); |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
915 continue; |
18002
4dc3c0cacd25
lib-http: client: Handle situation in which server sends response before request payload is fully sent.
Stephan Bosch <stephan@rename-it.nl>
parents:
18001
diff
changeset
|
916 } else if (!req->payload_sync && |
4dc3c0cacd25
lib-http: client: Handle situation in which server sends response before request payload is fully sent.
Stephan Bosch <stephan@rename-it.nl>
parents:
18001
diff
changeset
|
917 req->state == HTTP_REQUEST_STATE_PAYLOAD_OUT) { |
4dc3c0cacd25
lib-http: client: Handle situation in which server sends response before request payload is fully sent.
Stephan Bosch <stephan@rename-it.nl>
parents:
18001
diff
changeset
|
918 /* got early response from server while we're still sending request |
4dc3c0cacd25
lib-http: client: Handle situation in which server sends response before request payload is fully sent.
Stephan Bosch <stephan@rename-it.nl>
parents:
18001
diff
changeset
|
919 payload. we cannot recover from this reliably, so we stop sending |
4dc3c0cacd25
lib-http: client: Handle situation in which server sends response before request payload is fully sent.
Stephan Bosch <stephan@rename-it.nl>
parents:
18001
diff
changeset
|
920 payload and close the connection once the response is processed */ |
4dc3c0cacd25
lib-http: client: Handle situation in which server sends response before request payload is fully sent.
Stephan Bosch <stephan@rename-it.nl>
parents:
18001
diff
changeset
|
921 http_client_connection_debug(conn, |
4dc3c0cacd25
lib-http: client: Handle situation in which server sends response before request payload is fully sent.
Stephan Bosch <stephan@rename-it.nl>
parents:
18001
diff
changeset
|
922 "Got early input from server; " |
4dc3c0cacd25
lib-http: client: Handle situation in which server sends response before request payload is fully sent.
Stephan Bosch <stephan@rename-it.nl>
parents:
18001
diff
changeset
|
923 "request payload not completely sent (will close connection)"); |
4dc3c0cacd25
lib-http: client: Handle situation in which server sends response before request payload is fully sent.
Stephan Bosch <stephan@rename-it.nl>
parents:
18001
diff
changeset
|
924 o_stream_unset_flush_callback(conn->conn.output); |
4dc3c0cacd25
lib-http: client: Handle situation in which server sends response before request payload is fully sent.
Stephan Bosch <stephan@rename-it.nl>
parents:
18001
diff
changeset
|
925 conn->output_broken = early = TRUE; |
18001
cffa8349f167
lib-http: client: Fixed handling of requests aborted while still sending payload to server.
Stephan Bosch <stephan@rename-it.nl>
parents:
17999
diff
changeset
|
926 } |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
927 |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
928 http_client_connection_debug(conn, |
17625
b162e39909d7
lib-http: Debug log now includes where HTTP requests spent their time on.
Timo Sirainen <tss@iki.fi>
parents:
17610
diff
changeset
|
929 "Got %u response for request %s (took %u ms + %u ms in queue)", |
b162e39909d7
lib-http: Debug log now includes where HTTP requests spent their time on.
Timo Sirainen <tss@iki.fi>
parents:
17610
diff
changeset
|
930 response.status, http_client_request_label(req), |
b162e39909d7
lib-http: Debug log now includes where HTTP requests spent their time on.
Timo Sirainen <tss@iki.fi>
parents:
17610
diff
changeset
|
931 timeval_diff_msecs(&req->response_time, &req->sent_time), |
b162e39909d7
lib-http: Debug log now includes where HTTP requests spent their time on.
Timo Sirainen <tss@iki.fi>
parents:
17610
diff
changeset
|
932 timeval_diff_msecs(&req->sent_time, &req->submit_time)); |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
933 |
16756
7fc1dcfc5e3a
lib-http: http-client: Fixed segfault caused by earlier improvement of connection output locking.
Stephan Bosch <stephan@rename-it.nl>
parents:
16745
diff
changeset
|
934 /* make sure connection output is unlocked if 100-continue failed */ |
19727
8f72e4f0ed5d
lib-http: client: Fixed pipelining bug: client sometimes sent new request while still waiting for 100-continue.
Stephan Bosch <stephan@rename-it.nl>
parents:
19726
diff
changeset
|
935 if (req->payload_sync && !req->payload_sync_continue) { |
8f72e4f0ed5d
lib-http: client: Fixed pipelining bug: client sometimes sent new request while still waiting for 100-continue.
Stephan Bosch <stephan@rename-it.nl>
parents:
19726
diff
changeset
|
936 http_client_connection_debug(conn, "Unlocked output"); |
8f72e4f0ed5d
lib-http: client: Fixed pipelining bug: client sometimes sent new request while still waiting for 100-continue.
Stephan Bosch <stephan@rename-it.nl>
parents:
19726
diff
changeset
|
937 conn->output_locked = FALSE; |
8f72e4f0ed5d
lib-http: client: Fixed pipelining bug: client sometimes sent new request while still waiting for 100-continue.
Stephan Bosch <stephan@rename-it.nl>
parents:
19726
diff
changeset
|
938 } |
16756
7fc1dcfc5e3a
lib-http: http-client: Fixed segfault caused by earlier improvement of connection output locking.
Stephan Bosch <stephan@rename-it.nl>
parents:
16745
diff
changeset
|
939 |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
940 /* remove request from queue */ |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
941 array_delete(&conn->request_wait_list, 0, 1); |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
942 aborted = (req->state == HTTP_REQUEST_STATE_ABORTED); |
19817
fa23955f6028
lib-http: http_client_request_unref() now always sets *req=NULL
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19816
diff
changeset
|
943 req_ref = req; |
21425
70083e131e22
lib-http: client: Make sure req->conn is only not NULL when that connection holds a reference to that request.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21424
diff
changeset
|
944 if (!http_client_connection_unref_request(conn, &req_ref)) { |
19817
fa23955f6028
lib-http: http_client_request_unref() now always sets *req=NULL
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19816
diff
changeset
|
945 i_assert(aborted); |
fa23955f6028
lib-http: http_client_request_unref() now always sets *req=NULL
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19816
diff
changeset
|
946 req = NULL; |
fa23955f6028
lib-http: http_client_request_unref() now always sets *req=NULL
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19816
diff
changeset
|
947 } |
21425
70083e131e22
lib-http: client: Make sure req->conn is only not NULL when that connection holds a reference to that request.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21424
diff
changeset
|
948 |
16740
adb4d013073d
lib-http: Adjusted response and request parsers to accept a request/response object to fill with data, rather than have it return one.
Stephan Bosch <stephan@rename-it.nl>
parents:
16739
diff
changeset
|
949 conn->close_indicated = response.connection_close; |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
950 |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
951 if (!aborted) { |
17005
d2f2423615d7
http: Implemented delayed requests scheduling.
Stephan Bosch <stephan@rename-it.nl>
parents:
16941
diff
changeset
|
952 bool handled = FALSE; |
d2f2423615d7
http: Implemented delayed requests scheduling.
Stephan Bosch <stephan@rename-it.nl>
parents:
16941
diff
changeset
|
953 |
18002
4dc3c0cacd25
lib-http: client: Handle situation in which server sends response before request payload is fully sent.
Stephan Bosch <stephan@rename-it.nl>
parents:
18001
diff
changeset
|
954 /* response cannot be 2xx if request payload was not completely sent |
4dc3c0cacd25
lib-http: client: Handle situation in which server sends response before request payload is fully sent.
Stephan Bosch <stephan@rename-it.nl>
parents:
18001
diff
changeset
|
955 */ |
4dc3c0cacd25
lib-http: client: Handle situation in which server sends response before request payload is fully sent.
Stephan Bosch <stephan@rename-it.nl>
parents:
18001
diff
changeset
|
956 if (early && response.status / 100 == 2) { |
20344
2b71a1c2febc
lib-http: Changed http_client_request_error to set request to NULL
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19961
diff
changeset
|
957 http_client_request_error(&req, |
18002
4dc3c0cacd25
lib-http: client: Handle situation in which server sends response before request payload is fully sent.
Stephan Bosch <stephan@rename-it.nl>
parents:
18001
diff
changeset
|
958 HTTP_CLIENT_REQUEST_ERROR_BAD_RESPONSE, |
4dc3c0cacd25
lib-http: client: Handle situation in which server sends response before request payload is fully sent.
Stephan Bosch <stephan@rename-it.nl>
parents:
18001
diff
changeset
|
959 "Server responded with success response " |
4dc3c0cacd25
lib-http: client: Handle situation in which server sends response before request payload is fully sent.
Stephan Bosch <stephan@rename-it.nl>
parents:
18001
diff
changeset
|
960 "before all payload was sent"); |
4dc3c0cacd25
lib-http: client: Handle situation in which server sends response before request payload is fully sent.
Stephan Bosch <stephan@rename-it.nl>
parents:
18001
diff
changeset
|
961 http_client_connection_close(&conn); |
4dc3c0cacd25
lib-http: client: Handle situation in which server sends response before request payload is fully sent.
Stephan Bosch <stephan@rename-it.nl>
parents:
18001
diff
changeset
|
962 return; |
4dc3c0cacd25
lib-http: client: Handle situation in which server sends response before request payload is fully sent.
Stephan Bosch <stephan@rename-it.nl>
parents:
18001
diff
changeset
|
963 } |
4dc3c0cacd25
lib-http: client: Handle situation in which server sends response before request payload is fully sent.
Stephan Bosch <stephan@rename-it.nl>
parents:
18001
diff
changeset
|
964 |
17052
353c3e3edc52
lib-http: Don't try to automatically retry requests whose payload was already lost.
Timo Sirainen <tss@iki.fi>
parents:
17009
diff
changeset
|
965 /* don't redirect/retry if we're sending data in small |
353c3e3edc52
lib-http: Don't try to automatically retry requests whose payload was already lost.
Timo Sirainen <tss@iki.fi>
parents:
17009
diff
changeset
|
966 blocks via http_client_request_send_payload() |
353c3e3edc52
lib-http: Don't try to automatically retry requests whose payload was already lost.
Timo Sirainen <tss@iki.fi>
parents:
17009
diff
changeset
|
967 and we're not waiting for 100 continue */ |
353c3e3edc52
lib-http: Don't try to automatically retry requests whose payload was already lost.
Timo Sirainen <tss@iki.fi>
parents:
17009
diff
changeset
|
968 if (!req->payload_wait || |
19727
8f72e4f0ed5d
lib-http: client: Fixed pipelining bug: client sometimes sent new request while still waiting for 100-continue.
Stephan Bosch <stephan@rename-it.nl>
parents:
19726
diff
changeset
|
969 (req->payload_sync && !req->payload_sync_continue)) { |
17052
353c3e3edc52
lib-http: Don't try to automatically retry requests whose payload was already lost.
Timo Sirainen <tss@iki.fi>
parents:
17009
diff
changeset
|
970 /* failed Expect: */ |
353c3e3edc52
lib-http: Don't try to automatically retry requests whose payload was already lost.
Timo Sirainen <tss@iki.fi>
parents:
17009
diff
changeset
|
971 if (response.status == 417 && req->payload_sync) { |
353c3e3edc52
lib-http: Don't try to automatically retry requests whose payload was already lost.
Timo Sirainen <tss@iki.fi>
parents:
17009
diff
changeset
|
972 /* drop Expect: continue */ |
353c3e3edc52
lib-http: Don't try to automatically retry requests whose payload was already lost.
Timo Sirainen <tss@iki.fi>
parents:
17009
diff
changeset
|
973 req->payload_sync = FALSE; |
353c3e3edc52
lib-http: Don't try to automatically retry requests whose payload was already lost.
Timo Sirainen <tss@iki.fi>
parents:
17009
diff
changeset
|
974 conn->output_locked = FALSE; |
353c3e3edc52
lib-http: Don't try to automatically retry requests whose payload was already lost.
Timo Sirainen <tss@iki.fi>
parents:
17009
diff
changeset
|
975 conn->peer->no_payload_sync = TRUE; |
353c3e3edc52
lib-http: Don't try to automatically retry requests whose payload was already lost.
Timo Sirainen <tss@iki.fi>
parents:
17009
diff
changeset
|
976 if (http_client_request_try_retry(req)) |
353c3e3edc52
lib-http: Don't try to automatically retry requests whose payload was already lost.
Timo Sirainen <tss@iki.fi>
parents:
17009
diff
changeset
|
977 handled = TRUE; |
353c3e3edc52
lib-http: Don't try to automatically retry requests whose payload was already lost.
Timo Sirainen <tss@iki.fi>
parents:
17009
diff
changeset
|
978 /* redirection */ |
353c3e3edc52
lib-http: Don't try to automatically retry requests whose payload was already lost.
Timo Sirainen <tss@iki.fi>
parents:
17009
diff
changeset
|
979 } else if (!req->client->set.no_auto_redirect && |
353c3e3edc52
lib-http: Don't try to automatically retry requests whose payload was already lost.
Timo Sirainen <tss@iki.fi>
parents:
17009
diff
changeset
|
980 response.status / 100 == 3 && response.status != 304 && |
353c3e3edc52
lib-http: Don't try to automatically retry requests whose payload was already lost.
Timo Sirainen <tss@iki.fi>
parents:
17009
diff
changeset
|
981 response.location != NULL) { |
353c3e3edc52
lib-http: Don't try to automatically retry requests whose payload was already lost.
Timo Sirainen <tss@iki.fi>
parents:
17009
diff
changeset
|
982 /* redirect (possibly after delay) */ |
353c3e3edc52
lib-http: Don't try to automatically retry requests whose payload was already lost.
Timo Sirainen <tss@iki.fi>
parents:
17009
diff
changeset
|
983 if (http_client_request_delay_from_response(req, &response) >= 0) { |
353c3e3edc52
lib-http: Don't try to automatically retry requests whose payload was already lost.
Timo Sirainen <tss@iki.fi>
parents:
17009
diff
changeset
|
984 http_client_request_redirect |
353c3e3edc52
lib-http: Don't try to automatically retry requests whose payload was already lost.
Timo Sirainen <tss@iki.fi>
parents:
17009
diff
changeset
|
985 (req, response.status, response.location); |
353c3e3edc52
lib-http: Don't try to automatically retry requests whose payload was already lost.
Timo Sirainen <tss@iki.fi>
parents:
17009
diff
changeset
|
986 handled = TRUE; |
353c3e3edc52
lib-http: Don't try to automatically retry requests whose payload was already lost.
Timo Sirainen <tss@iki.fi>
parents:
17009
diff
changeset
|
987 } |
353c3e3edc52
lib-http: Don't try to automatically retry requests whose payload was already lost.
Timo Sirainen <tss@iki.fi>
parents:
17009
diff
changeset
|
988 /* service unavailable */ |
353c3e3edc52
lib-http: Don't try to automatically retry requests whose payload was already lost.
Timo Sirainen <tss@iki.fi>
parents:
17009
diff
changeset
|
989 } else if (response.status == 503) { |
353c3e3edc52
lib-http: Don't try to automatically retry requests whose payload was already lost.
Timo Sirainen <tss@iki.fi>
parents:
17009
diff
changeset
|
990 /* automatically retry after delay if indicated */ |
353c3e3edc52
lib-http: Don't try to automatically retry requests whose payload was already lost.
Timo Sirainen <tss@iki.fi>
parents:
17009
diff
changeset
|
991 if ( response.retry_after != (time_t)-1 && |
353c3e3edc52
lib-http: Don't try to automatically retry requests whose payload was already lost.
Timo Sirainen <tss@iki.fi>
parents:
17009
diff
changeset
|
992 http_client_request_delay_from_response(req, &response) > 0 && |
353c3e3edc52
lib-http: Don't try to automatically retry requests whose payload was already lost.
Timo Sirainen <tss@iki.fi>
parents:
17009
diff
changeset
|
993 http_client_request_try_retry(req)) |
353c3e3edc52
lib-http: Don't try to automatically retry requests whose payload was already lost.
Timo Sirainen <tss@iki.fi>
parents:
17009
diff
changeset
|
994 handled = TRUE; |
19033
a8e01e385e90
lib-http: client: Added proper handling of 408 response status.
Stephan Bosch <stephan@rename-it.nl>
parents:
18969
diff
changeset
|
995 /* request timeout (by server) */ |
a8e01e385e90
lib-http: client: Added proper handling of 408 response status.
Stephan Bosch <stephan@rename-it.nl>
parents:
18969
diff
changeset
|
996 } else if (response.status == 408) { |
a8e01e385e90
lib-http: client: Added proper handling of 408 response status.
Stephan Bosch <stephan@rename-it.nl>
parents:
18969
diff
changeset
|
997 /* automatically retry */ |
a8e01e385e90
lib-http: client: Added proper handling of 408 response status.
Stephan Bosch <stephan@rename-it.nl>
parents:
18969
diff
changeset
|
998 if (http_client_request_try_retry(req)) |
a8e01e385e90
lib-http: client: Added proper handling of 408 response status.
Stephan Bosch <stephan@rename-it.nl>
parents:
18969
diff
changeset
|
999 handled = TRUE; |
a8e01e385e90
lib-http: client: Added proper handling of 408 response status.
Stephan Bosch <stephan@rename-it.nl>
parents:
18969
diff
changeset
|
1000 /* connection close is implicit, although server should indicate |
a8e01e385e90
lib-http: client: Added proper handling of 408 response status.
Stephan Bosch <stephan@rename-it.nl>
parents:
18969
diff
changeset
|
1001 that explicitly */ |
a8e01e385e90
lib-http: client: Added proper handling of 408 response status.
Stephan Bosch <stephan@rename-it.nl>
parents:
18969
diff
changeset
|
1002 conn->close_indicated = TRUE; |
17005
d2f2423615d7
http: Implemented delayed requests scheduling.
Stephan Bosch <stephan@rename-it.nl>
parents:
16941
diff
changeset
|
1003 } |
d2f2423615d7
http: Implemented delayed requests scheduling.
Stephan Bosch <stephan@rename-it.nl>
parents:
16941
diff
changeset
|
1004 } |
d2f2423615d7
http: Implemented delayed requests scheduling.
Stephan Bosch <stephan@rename-it.nl>
parents:
16941
diff
changeset
|
1005 |
d2f2423615d7
http: Implemented delayed requests scheduling.
Stephan Bosch <stephan@rename-it.nl>
parents:
16941
diff
changeset
|
1006 if (!handled) { |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1007 /* response for application */ |
20347
7e8ed1fa25bd
lib-http: client: Improved request reference counting in connection code.
Stephan Bosch <stephan@dovecot.fi>
parents:
20346
diff
changeset
|
1008 if (!http_client_connection_return_response |
7e8ed1fa25bd
lib-http: client: Improved request reference counting in connection code.
Stephan Bosch <stephan@dovecot.fi>
parents:
20346
diff
changeset
|
1009 (conn, req, &response)) |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1010 return; |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1011 } |
17998
9c6318786455
lib-http: client: Aborted requests were not counted as finished in the connection's response receive loop.
Stephan Bosch <stephan@rename-it.nl>
parents:
17987
diff
changeset
|
1012 } |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1013 |
17998
9c6318786455
lib-http: client: Aborted requests were not counted as finished in the connection's response receive loop.
Stephan Bosch <stephan@rename-it.nl>
parents:
17987
diff
changeset
|
1014 finished++; |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1015 |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1016 /* server closing connection? */ |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1017 if (conn->close_indicated) { |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1018 http_client_connection_server_close(&conn); |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1019 return; |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1020 } |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1021 |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1022 /* get next waiting request */ |
18001
cffa8349f167
lib-http: client: Fixed handling of requests aborted while still sending payload to server.
Stephan Bosch <stephan@rename-it.nl>
parents:
17999
diff
changeset
|
1023 reqs = array_get(&conn->request_wait_list, &count); |
cffa8349f167
lib-http: client: Fixed handling of requests aborted while still sending payload to server.
Stephan Bosch <stephan@rename-it.nl>
parents:
17999
diff
changeset
|
1024 if (count > 0) { |
cffa8349f167
lib-http: client: Fixed handling of requests aborted while still sending payload to server.
Stephan Bosch <stephan@rename-it.nl>
parents:
17999
diff
changeset
|
1025 req = reqs[0]; |
16855
c3884a6acde6
lib-http: Added support for creating CONNECT tunnels through HTTP.
Stephan Bosch <stephan@rename-it.nl>
parents:
16852
diff
changeset
|
1026 |
c3884a6acde6
lib-http: Added support for creating CONNECT tunnels through HTTP.
Stephan Bosch <stephan@rename-it.nl>
parents:
16852
diff
changeset
|
1027 /* determine whether to expect a response payload */ |
c3884a6acde6
lib-http: Added support for creating CONNECT tunnels through HTTP.
Stephan Bosch <stephan@rename-it.nl>
parents:
16852
diff
changeset
|
1028 payload_type = http_client_request_get_payload_type(req); |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1029 } else { |
16451
a551409911f9
lib-http: Added connect and request timeout settings.
Timo Sirainen <tss@iki.fi>
parents:
16450
diff
changeset
|
1030 /* no more requests waiting for the connection */ |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1031 req = NULL; |
16855
c3884a6acde6
lib-http: Added support for creating CONNECT tunnels through HTTP.
Stephan Bosch <stephan@rename-it.nl>
parents:
16852
diff
changeset
|
1032 payload_type = HTTP_RESPONSE_PAYLOAD_TYPE_ALLOWED; |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1033 } |
18001
cffa8349f167
lib-http: client: Fixed handling of requests aborted while still sending payload to server.
Stephan Bosch <stephan@rename-it.nl>
parents:
17999
diff
changeset
|
1034 |
cffa8349f167
lib-http: client: Fixed handling of requests aborted while still sending payload to server.
Stephan Bosch <stephan@rename-it.nl>
parents:
17999
diff
changeset
|
1035 /* drop connection with broken output if last possible input was |
cffa8349f167
lib-http: client: Fixed handling of requests aborted while still sending payload to server.
Stephan Bosch <stephan@rename-it.nl>
parents:
17999
diff
changeset
|
1036 received */ |
cffa8349f167
lib-http: client: Fixed handling of requests aborted while still sending payload to server.
Stephan Bosch <stephan@rename-it.nl>
parents:
17999
diff
changeset
|
1037 if (conn->output_broken && (count == 0 || |
cffa8349f167
lib-http: client: Fixed handling of requests aborted while still sending payload to server.
Stephan Bosch <stephan@rename-it.nl>
parents:
17999
diff
changeset
|
1038 (count == 1 && req->state == HTTP_REQUEST_STATE_ABORTED))) { |
cffa8349f167
lib-http: client: Fixed handling of requests aborted while still sending payload to server.
Stephan Bosch <stephan@rename-it.nl>
parents:
17999
diff
changeset
|
1039 http_client_connection_server_close(&conn); |
cffa8349f167
lib-http: client: Fixed handling of requests aborted while still sending payload to server.
Stephan Bosch <stephan@rename-it.nl>
parents:
17999
diff
changeset
|
1040 return; |
cffa8349f167
lib-http: client: Fixed handling of requests aborted while still sending payload to server.
Stephan Bosch <stephan@rename-it.nl>
parents:
17999
diff
changeset
|
1041 } |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1042 } |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1043 |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1044 if (ret <= 0 && |
15999
f89ebdc1625d
lib-http: If we get disconnected, say exactly what the error was.
Timo Sirainen <tss@iki.fi>
parents:
15879
diff
changeset
|
1045 (conn->conn.input->eof || conn->conn.input->stream_errno != 0)) { |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1046 int stream_errno = conn->conn.input->stream_errno; |
21333
f7bc77720fe5
lib-http: client: Consolidated connection loss handling into a single function.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21108
diff
changeset
|
1047 http_client_connection_lost(&conn, |
f7bc77720fe5
lib-http: client: Consolidated connection loss handling into a single function.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21108
diff
changeset
|
1048 t_strdup_printf("read(%s) failed: %s", |
15999
f89ebdc1625d
lib-http: If we get disconnected, say exactly what the error was.
Timo Sirainen <tss@iki.fi>
parents:
15879
diff
changeset
|
1049 i_stream_get_name(conn->conn.input), |
f89ebdc1625d
lib-http: If we get disconnected, say exactly what the error was.
Timo Sirainen <tss@iki.fi>
parents:
15879
diff
changeset
|
1050 stream_errno != 0 ? |
16941
e67095b8486e
lib-http: Use [io]_stream_get_error() instead of just errno strings.
Timo Sirainen <tss@iki.fi>
parents:
16856
diff
changeset
|
1051 i_stream_get_error(conn->conn.input) : |
e67095b8486e
lib-http: Use [io]_stream_get_error() instead of just errno strings.
Timo Sirainen <tss@iki.fi>
parents:
16856
diff
changeset
|
1052 "EOF")); |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1053 return; |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1054 } |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1055 |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1056 if (ret < 0) { |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1057 http_client_connection_abort_error(&conn, |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1058 HTTP_CLIENT_REQUEST_ERROR_BAD_RESPONSE, error); |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1059 return; |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1060 } |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1061 |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1062 if (finished > 0) { |
16733
bdc5d6dcfc53
lib-http: http-client: Fixed request scheduling and connection management.
Stephan Bosch <stephan@rename-it.nl>
parents:
16731
diff
changeset
|
1063 /* connection still alive after (at least one) request; |
bdc5d6dcfc53
lib-http: http-client: Fixed request scheduling and connection management.
Stephan Bosch <stephan@rename-it.nl>
parents:
16731
diff
changeset
|
1064 we can pipeline -> mark for subsequent connections */ |
bdc5d6dcfc53
lib-http: http-client: Fixed request scheduling and connection management.
Stephan Bosch <stephan@rename-it.nl>
parents:
16731
diff
changeset
|
1065 conn->peer->allows_pipelining = TRUE; |
bdc5d6dcfc53
lib-http: http-client: Fixed request scheduling and connection management.
Stephan Bosch <stephan@rename-it.nl>
parents:
16731
diff
changeset
|
1066 |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1067 /* room for new requests */ |
20355
6335d6256a58
lib-http: client: Fixed bug in handling of lost connections while returning from another ioloop.
Stephan Bosch <stephan@dovecot.fi>
parents:
20354
diff
changeset
|
1068 if (http_client_connection_check_ready(conn) > 0) |
16733
bdc5d6dcfc53
lib-http: http-client: Fixed request scheduling and connection management.
Stephan Bosch <stephan@rename-it.nl>
parents:
16731
diff
changeset
|
1069 http_client_peer_trigger_request_handler(conn->peer); |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1070 } |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1071 } |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1072 |
16739
a6ed95a30cb1
lib-http: Added support for asynchronous payload for requests.
Stephan Bosch <stephan@rename-it.nl>
parents:
16733
diff
changeset
|
1073 int http_client_connection_output(struct http_client_connection *conn) |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1074 { |
18001
cffa8349f167
lib-http: client: Fixed handling of requests aborted while still sending payload to server.
Stephan Bosch <stephan@rename-it.nl>
parents:
17999
diff
changeset
|
1075 struct http_client_request *const *reqs; |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1076 struct ostream *output = conn->conn.output; |
18001
cffa8349f167
lib-http: client: Fixed handling of requests aborted while still sending payload to server.
Stephan Bosch <stephan@rename-it.nl>
parents:
17999
diff
changeset
|
1077 unsigned int count; |
15999
f89ebdc1625d
lib-http: If we get disconnected, say exactly what the error was.
Timo Sirainen <tss@iki.fi>
parents:
15879
diff
changeset
|
1078 const char *error; |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1079 int ret; |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1080 |
18969
a08e79a3707f
lib-http: client: Fixed handling of request timeout.
Stephan Bosch <stephan@rename-it.nl>
parents:
18494
diff
changeset
|
1081 /* we've seen activity from the server; reset request timeout */ |
a08e79a3707f
lib-http: client: Fixed handling of request timeout.
Stephan Bosch <stephan@rename-it.nl>
parents:
18494
diff
changeset
|
1082 http_client_connection_reset_request_timeout(conn); |
16451
a551409911f9
lib-http: Added connect and request timeout settings.
Timo Sirainen <tss@iki.fi>
parents:
16450
diff
changeset
|
1083 |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1084 if ((ret = o_stream_flush(output)) <= 0) { |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1085 if (ret < 0) { |
21333
f7bc77720fe5
lib-http: client: Consolidated connection loss handling into a single function.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21108
diff
changeset
|
1086 http_client_connection_lost(&conn, |
f7bc77720fe5
lib-http: client: Consolidated connection loss handling into a single function.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21108
diff
changeset
|
1087 t_strdup_printf("write(%s) failed: %s", |
16941
e67095b8486e
lib-http: Use [io]_stream_get_error() instead of just errno strings.
Timo Sirainen <tss@iki.fi>
parents:
16856
diff
changeset
|
1088 o_stream_get_name(output), |
e67095b8486e
lib-http: Use [io]_stream_get_error() instead of just errno strings.
Timo Sirainen <tss@iki.fi>
parents:
16856
diff
changeset
|
1089 o_stream_get_error(output))); |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1090 } |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1091 return ret; |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1092 } |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1093 |
18001
cffa8349f167
lib-http: client: Fixed handling of requests aborted while still sending payload to server.
Stephan Bosch <stephan@rename-it.nl>
parents:
17999
diff
changeset
|
1094 i_assert(!conn->output_broken); |
cffa8349f167
lib-http: client: Fixed handling of requests aborted while still sending payload to server.
Stephan Bosch <stephan@rename-it.nl>
parents:
17999
diff
changeset
|
1095 |
17970
7d3325713356
lib-http: client: Connection erroneously indicated that it was ready while SSL handshake was not yet completed.
Stephan Bosch <stephan@rename-it.nl>
parents:
17968
diff
changeset
|
1096 if (conn->ssl_iostream != NULL && |
7d3325713356
lib-http: client: Connection erroneously indicated that it was ready while SSL handshake was not yet completed.
Stephan Bosch <stephan@rename-it.nl>
parents:
17968
diff
changeset
|
1097 !ssl_iostream_is_handshaked(conn->ssl_iostream)) |
7d3325713356
lib-http: client: Connection erroneously indicated that it was ready while SSL handshake was not yet completed.
Stephan Bosch <stephan@rename-it.nl>
parents:
17968
diff
changeset
|
1098 return 1; |
7d3325713356
lib-http: client: Connection erroneously indicated that it was ready while SSL handshake was not yet completed.
Stephan Bosch <stephan@rename-it.nl>
parents:
17968
diff
changeset
|
1099 |
18001
cffa8349f167
lib-http: client: Fixed handling of requests aborted while still sending payload to server.
Stephan Bosch <stephan@rename-it.nl>
parents:
17999
diff
changeset
|
1100 reqs = array_get(&conn->request_wait_list, &count); |
cffa8349f167
lib-http: client: Fixed handling of requests aborted while still sending payload to server.
Stephan Bosch <stephan@rename-it.nl>
parents:
17999
diff
changeset
|
1101 if (count > 0 && conn->output_locked) { |
cffa8349f167
lib-http: client: Fixed handling of requests aborted while still sending payload to server.
Stephan Bosch <stephan@rename-it.nl>
parents:
17999
diff
changeset
|
1102 struct http_client_request *req = reqs[count-1]; |
19961
3f6a74b9ce54
lib-http: client: Fixed request timeout handling during pipelining.
Stephan Bosch <stephan@rename-it.nl>
parents:
19937
diff
changeset
|
1103 bool pipelined = (count > 1 || conn->pending_request != NULL); |
18001
cffa8349f167
lib-http: client: Fixed handling of requests aborted while still sending payload to server.
Stephan Bosch <stephan@rename-it.nl>
parents:
17999
diff
changeset
|
1104 |
cffa8349f167
lib-http: client: Fixed handling of requests aborted while still sending payload to server.
Stephan Bosch <stephan@rename-it.nl>
parents:
17999
diff
changeset
|
1105 if (req->state == HTTP_REQUEST_STATE_ABORTED) { |
cffa8349f167
lib-http: client: Fixed handling of requests aborted while still sending payload to server.
Stephan Bosch <stephan@rename-it.nl>
parents:
17999
diff
changeset
|
1106 http_client_connection_debug(conn, |
cffa8349f167
lib-http: client: Fixed handling of requests aborted while still sending payload to server.
Stephan Bosch <stephan@rename-it.nl>
parents:
17999
diff
changeset
|
1107 "Request aborted before sending payload was complete."); |
cffa8349f167
lib-http: client: Fixed handling of requests aborted while still sending payload to server.
Stephan Bosch <stephan@rename-it.nl>
parents:
17999
diff
changeset
|
1108 if (count == 1) { |
cffa8349f167
lib-http: client: Fixed handling of requests aborted while still sending payload to server.
Stephan Bosch <stephan@rename-it.nl>
parents:
17999
diff
changeset
|
1109 http_client_connection_close(&conn); |
cffa8349f167
lib-http: client: Fixed handling of requests aborted while still sending payload to server.
Stephan Bosch <stephan@rename-it.nl>
parents:
17999
diff
changeset
|
1110 } else { |
cffa8349f167
lib-http: client: Fixed handling of requests aborted while still sending payload to server.
Stephan Bosch <stephan@rename-it.nl>
parents:
17999
diff
changeset
|
1111 o_stream_unset_flush_callback(output); |
cffa8349f167
lib-http: client: Fixed handling of requests aborted while still sending payload to server.
Stephan Bosch <stephan@rename-it.nl>
parents:
17999
diff
changeset
|
1112 conn->output_broken = TRUE; |
cffa8349f167
lib-http: client: Fixed handling of requests aborted while still sending payload to server.
Stephan Bosch <stephan@rename-it.nl>
parents:
17999
diff
changeset
|
1113 } |
cffa8349f167
lib-http: client: Fixed handling of requests aborted while still sending payload to server.
Stephan Bosch <stephan@rename-it.nl>
parents:
17999
diff
changeset
|
1114 return 1; |
cffa8349f167
lib-http: client: Fixed handling of requests aborted while still sending payload to server.
Stephan Bosch <stephan@rename-it.nl>
parents:
17999
diff
changeset
|
1115 } |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1116 |
19727
8f72e4f0ed5d
lib-http: client: Fixed pipelining bug: client sometimes sent new request while still waiting for 100-continue.
Stephan Bosch <stephan@rename-it.nl>
parents:
19726
diff
changeset
|
1117 if (!req->payload_sync || req->payload_sync_continue) { |
19961
3f6a74b9ce54
lib-http: client: Fixed request timeout handling during pipelining.
Stephan Bosch <stephan@rename-it.nl>
parents:
19937
diff
changeset
|
1118 if (http_client_request_send_more(req, pipelined, &error) < 0) { |
21333
f7bc77720fe5
lib-http: client: Consolidated connection loss handling into a single function.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21108
diff
changeset
|
1119 http_client_connection_lost(&conn, error); |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1120 return -1; |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1121 } |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1122 if (!conn->output_locked) { |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1123 /* room for new requests */ |
20355
6335d6256a58
lib-http: client: Fixed bug in handling of lost connections while returning from another ioloop.
Stephan Bosch <stephan@dovecot.fi>
parents:
20354
diff
changeset
|
1124 if (http_client_connection_check_ready(conn) > 0) |
16733
bdc5d6dcfc53
lib-http: http-client: Fixed request scheduling and connection management.
Stephan Bosch <stephan@rename-it.nl>
parents:
16731
diff
changeset
|
1125 http_client_peer_trigger_request_handler(conn->peer); |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1126 } |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1127 } |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1128 } |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1129 return 1; |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1130 } |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1131 |
16855
c3884a6acde6
lib-http: Added support for creating CONNECT tunnels through HTTP.
Stephan Bosch <stephan@rename-it.nl>
parents:
16852
diff
changeset
|
1132 void |
c3884a6acde6
lib-http: Added support for creating CONNECT tunnels through HTTP.
Stephan Bosch <stephan@rename-it.nl>
parents:
16852
diff
changeset
|
1133 http_client_connection_start_tunnel(struct http_client_connection **_conn, |
c3884a6acde6
lib-http: Added support for creating CONNECT tunnels through HTTP.
Stephan Bosch <stephan@rename-it.nl>
parents:
16852
diff
changeset
|
1134 struct http_client_tunnel *tunnel) |
c3884a6acde6
lib-http: Added support for creating CONNECT tunnels through HTTP.
Stephan Bosch <stephan@rename-it.nl>
parents:
16852
diff
changeset
|
1135 { |
c3884a6acde6
lib-http: Added support for creating CONNECT tunnels through HTTP.
Stephan Bosch <stephan@rename-it.nl>
parents:
16852
diff
changeset
|
1136 struct http_client_connection *conn = *_conn; |
c3884a6acde6
lib-http: Added support for creating CONNECT tunnels through HTTP.
Stephan Bosch <stephan@rename-it.nl>
parents:
16852
diff
changeset
|
1137 |
c3884a6acde6
lib-http: Added support for creating CONNECT tunnels through HTTP.
Stephan Bosch <stephan@rename-it.nl>
parents:
16852
diff
changeset
|
1138 i_assert(conn->tunneling); |
c3884a6acde6
lib-http: Added support for creating CONNECT tunnels through HTTP.
Stephan Bosch <stephan@rename-it.nl>
parents:
16852
diff
changeset
|
1139 |
c3884a6acde6
lib-http: Added support for creating CONNECT tunnels through HTTP.
Stephan Bosch <stephan@rename-it.nl>
parents:
16852
diff
changeset
|
1140 /* claim connection streams */ |
21389
59437f8764c6
global: Replaced all instances of memset(p, 0, sizeof(*p)) with the new i_zero() macro.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21334
diff
changeset
|
1141 i_zero(tunnel); |
16855
c3884a6acde6
lib-http: Added support for creating CONNECT tunnels through HTTP.
Stephan Bosch <stephan@rename-it.nl>
parents:
16852
diff
changeset
|
1142 tunnel->input = conn->conn.input; |
c3884a6acde6
lib-http: Added support for creating CONNECT tunnels through HTTP.
Stephan Bosch <stephan@rename-it.nl>
parents:
16852
diff
changeset
|
1143 tunnel->output = conn->conn.output; |
c3884a6acde6
lib-http: Added support for creating CONNECT tunnels through HTTP.
Stephan Bosch <stephan@rename-it.nl>
parents:
16852
diff
changeset
|
1144 tunnel->fd_in = conn->conn.fd_in; |
c3884a6acde6
lib-http: Added support for creating CONNECT tunnels through HTTP.
Stephan Bosch <stephan@rename-it.nl>
parents:
16852
diff
changeset
|
1145 tunnel->fd_out = conn->conn.fd_out; |
c3884a6acde6
lib-http: Added support for creating CONNECT tunnels through HTTP.
Stephan Bosch <stephan@rename-it.nl>
parents:
16852
diff
changeset
|
1146 |
c3884a6acde6
lib-http: Added support for creating CONNECT tunnels through HTTP.
Stephan Bosch <stephan@rename-it.nl>
parents:
16852
diff
changeset
|
1147 /* detach from connection */ |
c3884a6acde6
lib-http: Added support for creating CONNECT tunnels through HTTP.
Stephan Bosch <stephan@rename-it.nl>
parents:
16852
diff
changeset
|
1148 conn->conn.input = NULL; |
c3884a6acde6
lib-http: Added support for creating CONNECT tunnels through HTTP.
Stephan Bosch <stephan@rename-it.nl>
parents:
16852
diff
changeset
|
1149 conn->conn.output = NULL; |
c3884a6acde6
lib-http: Added support for creating CONNECT tunnels through HTTP.
Stephan Bosch <stephan@rename-it.nl>
parents:
16852
diff
changeset
|
1150 conn->conn.fd_in = -1; |
c3884a6acde6
lib-http: Added support for creating CONNECT tunnels through HTTP.
Stephan Bosch <stephan@rename-it.nl>
parents:
16852
diff
changeset
|
1151 conn->conn.fd_out = -1; |
c3884a6acde6
lib-http: Added support for creating CONNECT tunnels through HTTP.
Stephan Bosch <stephan@rename-it.nl>
parents:
16852
diff
changeset
|
1152 conn->closing = TRUE; |
c3884a6acde6
lib-http: Added support for creating CONNECT tunnels through HTTP.
Stephan Bosch <stephan@rename-it.nl>
parents:
16852
diff
changeset
|
1153 conn->connected = FALSE; |
c3884a6acde6
lib-http: Added support for creating CONNECT tunnels through HTTP.
Stephan Bosch <stephan@rename-it.nl>
parents:
16852
diff
changeset
|
1154 connection_disconnect(&conn->conn); |
c3884a6acde6
lib-http: Added support for creating CONNECT tunnels through HTTP.
Stephan Bosch <stephan@rename-it.nl>
parents:
16852
diff
changeset
|
1155 |
c3884a6acde6
lib-http: Added support for creating CONNECT tunnels through HTTP.
Stephan Bosch <stephan@rename-it.nl>
parents:
16852
diff
changeset
|
1156 http_client_connection_unref(_conn); |
c3884a6acde6
lib-http: Added support for creating CONNECT tunnels through HTTP.
Stephan Bosch <stephan@rename-it.nl>
parents:
16852
diff
changeset
|
1157 } |
c3884a6acde6
lib-http: Added support for creating CONNECT tunnels through HTTP.
Stephan Bosch <stephan@rename-it.nl>
parents:
16852
diff
changeset
|
1158 |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1159 static void |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1160 http_client_connection_ready(struct http_client_connection *conn) |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1161 { |
17970
7d3325713356
lib-http: client: Connection erroneously indicated that it was ready while SSL handshake was not yet completed.
Stephan Bosch <stephan@rename-it.nl>
parents:
17968
diff
changeset
|
1162 http_client_connection_debug(conn, "Ready for requests"); |
7d3325713356
lib-http: client: Connection erroneously indicated that it was ready while SSL handshake was not yet completed.
Stephan Bosch <stephan@rename-it.nl>
parents:
17968
diff
changeset
|
1163 |
16733
bdc5d6dcfc53
lib-http: http-client: Fixed request scheduling and connection management.
Stephan Bosch <stephan@rename-it.nl>
parents:
16731
diff
changeset
|
1164 /* connected */ |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1165 conn->connected = TRUE; |
17882
77c4b78a4fa2
lib-http: Fixed detecting disconnection when ioloop is running only intermittently.
Stephan Bosch <stephan@rename-it.nl>
parents:
17881
diff
changeset
|
1166 conn->last_ioloop = current_ioloop; |
17970
7d3325713356
lib-http: client: Connection erroneously indicated that it was ready while SSL handshake was not yet completed.
Stephan Bosch <stephan@rename-it.nl>
parents:
17968
diff
changeset
|
1167 if (conn->to_connect != NULL) |
16451
a551409911f9
lib-http: Added connect and request timeout settings.
Timo Sirainen <tss@iki.fi>
parents:
16450
diff
changeset
|
1168 timeout_remove(&conn->to_connect); |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1169 |
16733
bdc5d6dcfc53
lib-http: http-client: Fixed request scheduling and connection management.
Stephan Bosch <stephan@rename-it.nl>
parents:
16731
diff
changeset
|
1170 /* indicate connection success */ |
bdc5d6dcfc53
lib-http: http-client: Fixed request scheduling and connection management.
Stephan Bosch <stephan@rename-it.nl>
parents:
16731
diff
changeset
|
1171 conn->connect_succeeded = TRUE; |
16483
07f72970bf61
lib-http: Added soft_connect_timeout_msecs setting to connect to multiple IPs in parallel.
Timo Sirainen <tss@iki.fi>
parents:
16460
diff
changeset
|
1172 http_client_peer_connection_success(conn->peer); |
07f72970bf61
lib-http: Added soft_connect_timeout_msecs setting to connect to multiple IPs in parallel.
Timo Sirainen <tss@iki.fi>
parents:
16460
diff
changeset
|
1173 |
16733
bdc5d6dcfc53
lib-http: http-client: Fixed request scheduling and connection management.
Stephan Bosch <stephan@rename-it.nl>
parents:
16731
diff
changeset
|
1174 /* start raw log */ |
17521
4bc7c1ad21a8
lib: Moved rawlog dir stat()s to iostream_rawlog_create() internally.
Timo Sirainen <tss@iki.fi>
parents:
17276
diff
changeset
|
1175 if (conn->client->set.rawlog_dir != NULL) { |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1176 iostream_rawlog_create(conn->client->set.rawlog_dir, |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1177 &conn->conn.input, &conn->conn.output); |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1178 } |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1179 |
16855
c3884a6acde6
lib-http: Added support for creating CONNECT tunnels through HTTP.
Stephan Bosch <stephan@rename-it.nl>
parents:
16852
diff
changeset
|
1180 /* direct tunneling connections handle connect requests just by providing a |
c3884a6acde6
lib-http: Added support for creating CONNECT tunnels through HTTP.
Stephan Bosch <stephan@rename-it.nl>
parents:
16852
diff
changeset
|
1181 raw connection */ |
c3884a6acde6
lib-http: Added support for creating CONNECT tunnels through HTTP.
Stephan Bosch <stephan@rename-it.nl>
parents:
16852
diff
changeset
|
1182 if (conn->peer->addr.type == HTTP_CLIENT_PEER_ADDR_RAW) { |
c3884a6acde6
lib-http: Added support for creating CONNECT tunnels through HTTP.
Stephan Bosch <stephan@rename-it.nl>
parents:
16852
diff
changeset
|
1183 struct http_client_request *req; |
c3884a6acde6
lib-http: Added support for creating CONNECT tunnels through HTTP.
Stephan Bosch <stephan@rename-it.nl>
parents:
16852
diff
changeset
|
1184 |
c3884a6acde6
lib-http: Added support for creating CONNECT tunnels through HTTP.
Stephan Bosch <stephan@rename-it.nl>
parents:
16852
diff
changeset
|
1185 req = http_client_peer_claim_request(conn->peer, FALSE); |
c3884a6acde6
lib-http: Added support for creating CONNECT tunnels through HTTP.
Stephan Bosch <stephan@rename-it.nl>
parents:
16852
diff
changeset
|
1186 if (req != NULL) { |
c3884a6acde6
lib-http: Added support for creating CONNECT tunnels through HTTP.
Stephan Bosch <stephan@rename-it.nl>
parents:
16852
diff
changeset
|
1187 struct http_response response; |
c3884a6acde6
lib-http: Added support for creating CONNECT tunnels through HTTP.
Stephan Bosch <stephan@rename-it.nl>
parents:
16852
diff
changeset
|
1188 |
c3884a6acde6
lib-http: Added support for creating CONNECT tunnels through HTTP.
Stephan Bosch <stephan@rename-it.nl>
parents:
16852
diff
changeset
|
1189 conn->tunneling = TRUE; |
c3884a6acde6
lib-http: Added support for creating CONNECT tunnels through HTTP.
Stephan Bosch <stephan@rename-it.nl>
parents:
16852
diff
changeset
|
1190 |
21389
59437f8764c6
global: Replaced all instances of memset(p, 0, sizeof(*p)) with the new i_zero() macro.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21334
diff
changeset
|
1191 i_zero(&response); |
16855
c3884a6acde6
lib-http: Added support for creating CONNECT tunnels through HTTP.
Stephan Bosch <stephan@rename-it.nl>
parents:
16852
diff
changeset
|
1192 response.status = 200; |
c3884a6acde6
lib-http: Added support for creating CONNECT tunnels through HTTP.
Stephan Bosch <stephan@rename-it.nl>
parents:
16852
diff
changeset
|
1193 response.reason = "OK"; |
c3884a6acde6
lib-http: Added support for creating CONNECT tunnels through HTTP.
Stephan Bosch <stephan@rename-it.nl>
parents:
16852
diff
changeset
|
1194 |
20347
7e8ed1fa25bd
lib-http: client: Improved request reference counting in connection code.
Stephan Bosch <stephan@dovecot.fi>
parents:
20346
diff
changeset
|
1195 (void)http_client_connection_return_response(conn, req, &response); |
16855
c3884a6acde6
lib-http: Added support for creating CONNECT tunnels through HTTP.
Stephan Bosch <stephan@rename-it.nl>
parents:
16852
diff
changeset
|
1196 return; |
c3884a6acde6
lib-http: Added support for creating CONNECT tunnels through HTTP.
Stephan Bosch <stephan@rename-it.nl>
parents:
16852
diff
changeset
|
1197 } |
c3884a6acde6
lib-http: Added support for creating CONNECT tunnels through HTTP.
Stephan Bosch <stephan@rename-it.nl>
parents:
16852
diff
changeset
|
1198 |
c3884a6acde6
lib-http: Added support for creating CONNECT tunnels through HTTP.
Stephan Bosch <stephan@rename-it.nl>
parents:
16852
diff
changeset
|
1199 http_client_connection_debug(conn, |
c3884a6acde6
lib-http: Added support for creating CONNECT tunnels through HTTP.
Stephan Bosch <stephan@rename-it.nl>
parents:
16852
diff
changeset
|
1200 "No raw connect requests pending; closing useless connection"); |
17968
c5f81685571f
lib-http: client: Fixed handling of connection timeouts.
Stephan Bosch <stephan@rename-it.nl>
parents:
17941
diff
changeset
|
1201 http_client_connection_close(&conn); |
16855
c3884a6acde6
lib-http: Added support for creating CONNECT tunnels through HTTP.
Stephan Bosch <stephan@rename-it.nl>
parents:
16852
diff
changeset
|
1202 return; |
c3884a6acde6
lib-http: Added support for creating CONNECT tunnels through HTTP.
Stephan Bosch <stephan@rename-it.nl>
parents:
16852
diff
changeset
|
1203 } |
c3884a6acde6
lib-http: Added support for creating CONNECT tunnels through HTTP.
Stephan Bosch <stephan@rename-it.nl>
parents:
16852
diff
changeset
|
1204 |
16733
bdc5d6dcfc53
lib-http: http-client: Fixed request scheduling and connection management.
Stephan Bosch <stephan@rename-it.nl>
parents:
16731
diff
changeset
|
1205 /* start protocol I/O */ |
16745
572b9a9031e7
lib-http: Implemented limits on overall HTTP header size, size of individual header fields and the number of fields in the header.
Stephan Bosch <stephan@rename-it.nl>
parents:
16740
diff
changeset
|
1206 conn->http_parser = http_response_parser_init |
22389
36a38929734d
lib-http: Restructured the header, message, request, and response parsers to have an extensible and consistent API using flags.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
22247
diff
changeset
|
1207 (conn->conn.input, &conn->client->set.response_hdr_limits, 0); |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1208 o_stream_set_flush_callback(conn->conn.output, |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1209 http_client_connection_output, conn); |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1210 } |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1211 |
16154
970914436288
lib-ssl-iostream: ssl_iostream_set_handshake_callback() API changed.
Timo Sirainen <tss@iki.fi>
parents:
16153
diff
changeset
|
1212 static int |
970914436288
lib-ssl-iostream: ssl_iostream_set_handshake_callback() API changed.
Timo Sirainen <tss@iki.fi>
parents:
16153
diff
changeset
|
1213 http_client_connection_ssl_handshaked(const char **error_r, void *context) |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1214 { |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1215 struct http_client_connection *conn = context; |
19039
8f8f768937f5
http-client: Added support for using an HTTP proxy running on a unix socket.
Stephan Bosch <stephan@rename-it.nl>
parents:
19035
diff
changeset
|
1216 const char *error, *host = conn->peer->addr.a.tcp.https_name; |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1217 |
16161
ef939a32de27
lib-ssl-iostream: Simplified certificate validation. Also give better error messages.
Timo Sirainen <tss@iki.fi>
parents:
16159
diff
changeset
|
1218 if (ssl_iostream_check_cert_validity(conn->ssl_iostream, host, &error) == 0) |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1219 http_client_connection_debug(conn, "SSL handshake successful"); |
16161
ef939a32de27
lib-ssl-iostream: Simplified certificate validation. Also give better error messages.
Timo Sirainen <tss@iki.fi>
parents:
16159
diff
changeset
|
1220 else if (conn->client->set.ssl_allow_invalid_cert) { |
ef939a32de27
lib-ssl-iostream: Simplified certificate validation. Also give better error messages.
Timo Sirainen <tss@iki.fi>
parents:
16159
diff
changeset
|
1221 http_client_connection_debug(conn, "SSL handshake successful, " |
ef939a32de27
lib-ssl-iostream: Simplified certificate validation. Also give better error messages.
Timo Sirainen <tss@iki.fi>
parents:
16159
diff
changeset
|
1222 "ignoring invalid certificate: %s", error); |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1223 } else { |
16161
ef939a32de27
lib-ssl-iostream: Simplified certificate validation. Also give better error messages.
Timo Sirainen <tss@iki.fi>
parents:
16159
diff
changeset
|
1224 *error_r = error; |
16156
4e9851e24c28
lib-ssl-iostream: If handshake callback fails, close the iostreams immediately.
Timo Sirainen <tss@iki.fi>
parents:
16155
diff
changeset
|
1225 return -1; |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1226 } |
16161
ef939a32de27
lib-ssl-iostream: Simplified certificate validation. Also give better error messages.
Timo Sirainen <tss@iki.fi>
parents:
16159
diff
changeset
|
1227 return 0; |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1228 } |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1229 |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1230 static int |
16153
3580439c06d8
lib-http: Pass connect failures all the way to request callback's error string.
Timo Sirainen <tss@iki.fi>
parents:
16152
diff
changeset
|
1231 http_client_connection_ssl_init(struct http_client_connection *conn, |
3580439c06d8
lib-http: Pass connect failures all the way to request callback's error string.
Timo Sirainen <tss@iki.fi>
parents:
16152
diff
changeset
|
1232 const char **error_r) |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1233 { |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1234 struct ssl_iostream_settings ssl_set; |
16159
f4bac0352464
lib-ssl-iostream: Added support for TLS SNI, which caused some API changes.
Timo Sirainen <tss@iki.fi>
parents:
16158
diff
changeset
|
1235 const char *error; |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1236 |
16153
3580439c06d8
lib-http: Pass connect failures all the way to request callback's error string.
Timo Sirainen <tss@iki.fi>
parents:
16152
diff
changeset
|
1237 i_assert(conn->client->ssl_ctx != NULL); |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1238 |
21389
59437f8764c6
global: Replaced all instances of memset(p, 0, sizeof(*p)) with the new i_zero() macro.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21334
diff
changeset
|
1239 i_zero(&ssl_set); |
16156
4e9851e24c28
lib-ssl-iostream: If handshake callback fails, close the iostreams immediately.
Timo Sirainen <tss@iki.fi>
parents:
16155
diff
changeset
|
1240 if (!conn->client->set.ssl_allow_invalid_cert) { |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1241 ssl_set.verbose_invalid_cert = TRUE; |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1242 ssl_set.verify_remote_cert = TRUE; |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1243 ssl_set.require_valid_cert = TRUE; |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1244 } |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1245 |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1246 if (conn->client->set.debug) |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1247 http_client_connection_debug(conn, "Starting SSL handshake"); |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1248 |
16159
f4bac0352464
lib-ssl-iostream: Added support for TLS SNI, which caused some API changes.
Timo Sirainen <tss@iki.fi>
parents:
16158
diff
changeset
|
1249 if (io_stream_create_ssl_client(conn->client->ssl_ctx, |
19039
8f8f768937f5
http-client: Added support for using an HTTP proxy running on a unix socket.
Stephan Bosch <stephan@rename-it.nl>
parents:
19035
diff
changeset
|
1250 conn->peer->addr.a.tcp.https_name, &ssl_set, |
16159
f4bac0352464
lib-ssl-iostream: Added support for TLS SNI, which caused some API changes.
Timo Sirainen <tss@iki.fi>
parents:
16158
diff
changeset
|
1251 &conn->conn.input, &conn->conn.output, |
f4bac0352464
lib-ssl-iostream: Added support for TLS SNI, which caused some API changes.
Timo Sirainen <tss@iki.fi>
parents:
16158
diff
changeset
|
1252 &conn->ssl_iostream, &error) < 0) { |
16153
3580439c06d8
lib-http: Pass connect failures all the way to request callback's error string.
Timo Sirainen <tss@iki.fi>
parents:
16152
diff
changeset
|
1253 *error_r = t_strdup_printf( |
3580439c06d8
lib-http: Pass connect failures all the way to request callback's error string.
Timo Sirainen <tss@iki.fi>
parents:
16152
diff
changeset
|
1254 "Couldn't initialize SSL client for %s: %s", |
3580439c06d8
lib-http: Pass connect failures all the way to request callback's error string.
Timo Sirainen <tss@iki.fi>
parents:
16152
diff
changeset
|
1255 conn->conn.name, error); |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1256 return -1; |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1257 } |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1258 ssl_iostream_set_handshake_callback(conn->ssl_iostream, |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1259 http_client_connection_ssl_handshaked, conn); |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1260 if (ssl_iostream_handshake(conn->ssl_iostream) < 0) { |
16153
3580439c06d8
lib-http: Pass connect failures all the way to request callback's error string.
Timo Sirainen <tss@iki.fi>
parents:
16152
diff
changeset
|
1261 *error_r = t_strdup_printf("SSL handshake to %s failed: %s", |
3580439c06d8
lib-http: Pass connect failures all the way to request callback's error string.
Timo Sirainen <tss@iki.fi>
parents:
16152
diff
changeset
|
1262 conn->conn.name, ssl_iostream_get_last_error(conn->ssl_iostream)); |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1263 return -1; |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1264 } |
16459
554774a328b9
lib-http: Fixed previous patch setting connection connected only after SSL handshake.
Timo Sirainen <tss@iki.fi>
parents:
16453
diff
changeset
|
1265 |
17970
7d3325713356
lib-http: client: Connection erroneously indicated that it was ready while SSL handshake was not yet completed.
Stephan Bosch <stephan@rename-it.nl>
parents:
17968
diff
changeset
|
1266 if (ssl_iostream_is_handshaked(conn->ssl_iostream)) { |
7d3325713356
lib-http: client: Connection erroneously indicated that it was ready while SSL handshake was not yet completed.
Stephan Bosch <stephan@rename-it.nl>
parents:
17968
diff
changeset
|
1267 http_client_connection_ready(conn); |
7d3325713356
lib-http: client: Connection erroneously indicated that it was ready while SSL handshake was not yet completed.
Stephan Bosch <stephan@rename-it.nl>
parents:
17968
diff
changeset
|
1268 } else { |
7d3325713356
lib-http: client: Connection erroneously indicated that it was ready while SSL handshake was not yet completed.
Stephan Bosch <stephan@rename-it.nl>
parents:
17968
diff
changeset
|
1269 /* wait for handshake to complete; connection input handler does the rest |
7d3325713356
lib-http: client: Connection erroneously indicated that it was ready while SSL handshake was not yet completed.
Stephan Bosch <stephan@rename-it.nl>
parents:
17968
diff
changeset
|
1270 by reading from the input stream */ |
7d3325713356
lib-http: client: Connection erroneously indicated that it was ready while SSL handshake was not yet completed.
Stephan Bosch <stephan@rename-it.nl>
parents:
17968
diff
changeset
|
1271 o_stream_set_flush_callback(conn->conn.output, |
7d3325713356
lib-http: client: Connection erroneously indicated that it was ready while SSL handshake was not yet completed.
Stephan Bosch <stephan@rename-it.nl>
parents:
17968
diff
changeset
|
1272 http_client_connection_output, conn); |
7d3325713356
lib-http: client: Connection erroneously indicated that it was ready while SSL handshake was not yet completed.
Stephan Bosch <stephan@rename-it.nl>
parents:
17968
diff
changeset
|
1273 } |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1274 return 0; |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1275 } |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1276 |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1277 static void |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1278 http_client_connection_connected(struct connection *_conn, bool success) |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1279 { |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1280 struct http_client_connection *conn = |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1281 (struct http_client_connection *)_conn; |
20352
ebdd1bc4dc16
lib-http: client: Added settings to configure the connection's socket kernel buffer sizes.
Stephan Bosch <stephan@dovecot.fi>
parents:
20347
diff
changeset
|
1282 const struct http_client_settings *set = &conn->client->set; |
16153
3580439c06d8
lib-http: Pass connect failures all the way to request callback's error string.
Timo Sirainen <tss@iki.fi>
parents:
16152
diff
changeset
|
1283 const char *error; |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1284 |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1285 if (!success) { |
21029
a3a045122aa4
lib-http: client: Created http_client_connection_failure() handler.
Stephan Bosch <stephan@dovecot.fi>
parents:
21028
diff
changeset
|
1286 http_client_connection_failure(conn, t_strdup_printf( |
16153
3580439c06d8
lib-http: Pass connect failures all the way to request callback's error string.
Timo Sirainen <tss@iki.fi>
parents:
16152
diff
changeset
|
1287 "connect(%s) failed: %m", _conn->name)); |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1288 } else { |
16451
a551409911f9
lib-http: Added connect and request timeout settings.
Timo Sirainen <tss@iki.fi>
parents:
16450
diff
changeset
|
1289 conn->connected_timestamp = ioloop_timeval; |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1290 http_client_connection_debug(conn, "Connected"); |
20352
ebdd1bc4dc16
lib-http: client: Added settings to configure the connection's socket kernel buffer sizes.
Stephan Bosch <stephan@dovecot.fi>
parents:
20347
diff
changeset
|
1291 |
21042
770b5fe8cc16
lib-http: client/server: Enable the TCP_NODELAY option for all connections.
Stephan Bosch <stephan@dovecot.fi>
parents:
21040
diff
changeset
|
1292 (void)net_set_tcp_nodelay(_conn->fd_out, TRUE); |
20352
ebdd1bc4dc16
lib-http: client: Added settings to configure the connection's socket kernel buffer sizes.
Stephan Bosch <stephan@dovecot.fi>
parents:
20347
diff
changeset
|
1293 if (set->socket_send_buffer_size > 0) { |
ebdd1bc4dc16
lib-http: client: Added settings to configure the connection's socket kernel buffer sizes.
Stephan Bosch <stephan@dovecot.fi>
parents:
20347
diff
changeset
|
1294 if (net_set_send_buffer_size(_conn->fd_out, |
ebdd1bc4dc16
lib-http: client: Added settings to configure the connection's socket kernel buffer sizes.
Stephan Bosch <stephan@dovecot.fi>
parents:
20347
diff
changeset
|
1295 set->socket_send_buffer_size) < 0) |
20361
b2d5a078b566
lib-http: Improved error logging for net_set_*_buffer_size() failures.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20355
diff
changeset
|
1296 i_error("net_set_send_buffer_size(%"PRIuSIZE_T") failed: %m", |
b2d5a078b566
lib-http: Improved error logging for net_set_*_buffer_size() failures.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20355
diff
changeset
|
1297 set->socket_send_buffer_size); |
20352
ebdd1bc4dc16
lib-http: client: Added settings to configure the connection's socket kernel buffer sizes.
Stephan Bosch <stephan@dovecot.fi>
parents:
20347
diff
changeset
|
1298 } |
ebdd1bc4dc16
lib-http: client: Added settings to configure the connection's socket kernel buffer sizes.
Stephan Bosch <stephan@dovecot.fi>
parents:
20347
diff
changeset
|
1299 if (set->socket_recv_buffer_size > 0) { |
ebdd1bc4dc16
lib-http: client: Added settings to configure the connection's socket kernel buffer sizes.
Stephan Bosch <stephan@dovecot.fi>
parents:
20347
diff
changeset
|
1300 if (net_set_recv_buffer_size(_conn->fd_in, |
ebdd1bc4dc16
lib-http: client: Added settings to configure the connection's socket kernel buffer sizes.
Stephan Bosch <stephan@dovecot.fi>
parents:
20347
diff
changeset
|
1301 set->socket_recv_buffer_size) < 0) |
20361
b2d5a078b566
lib-http: Improved error logging for net_set_*_buffer_size() failures.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20355
diff
changeset
|
1302 i_error("net_set_recv_buffer_size(%"PRIuSIZE_T") failed: %m", |
b2d5a078b566
lib-http: Improved error logging for net_set_*_buffer_size() failures.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20355
diff
changeset
|
1303 set->socket_recv_buffer_size); |
20352
ebdd1bc4dc16
lib-http: client: Added settings to configure the connection's socket kernel buffer sizes.
Stephan Bosch <stephan@dovecot.fi>
parents:
20347
diff
changeset
|
1304 } |
ebdd1bc4dc16
lib-http: client: Added settings to configure the connection's socket kernel buffer sizes.
Stephan Bosch <stephan@dovecot.fi>
parents:
20347
diff
changeset
|
1305 |
19039
8f8f768937f5
http-client: Added support for using an HTTP proxy running on a unix socket.
Stephan Bosch <stephan@rename-it.nl>
parents:
19035
diff
changeset
|
1306 if (http_client_peer_addr_is_https(&conn->peer->addr)) { |
16153
3580439c06d8
lib-http: Pass connect failures all the way to request callback's error string.
Timo Sirainen <tss@iki.fi>
parents:
16152
diff
changeset
|
1307 if (http_client_connection_ssl_init(conn, &error) < 0) { |
16574
a6b00756ab2c
lib-http: Added more debug messages.
Timo Sirainen <tss@iki.fi>
parents:
16572
diff
changeset
|
1308 http_client_connection_debug(conn, "%s", error); |
21029
a3a045122aa4
lib-http: client: Created http_client_connection_failure() handler.
Stephan Bosch <stephan@dovecot.fi>
parents:
21028
diff
changeset
|
1309 http_client_connection_failure(conn, error); |
17968
c5f81685571f
lib-http: client: Fixed handling of connection timeouts.
Stephan Bosch <stephan@rename-it.nl>
parents:
17941
diff
changeset
|
1310 http_client_connection_close(&conn); |
16150
d3921050f540
lib-http: If SSL init/handshake fails for connection, destroy it.
Timo Sirainen <tss@iki.fi>
parents:
16149
diff
changeset
|
1311 } |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1312 return; |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1313 } |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1314 http_client_connection_ready(conn); |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1315 } |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1316 } |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1317 |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1318 static const struct connection_settings http_client_connection_set = { |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1319 .input_max_size = (size_t)-1, |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1320 .output_max_size = (size_t)-1, |
19039
8f8f768937f5
http-client: Added support for using an HTTP proxy running on a unix socket.
Stephan Bosch <stephan@rename-it.nl>
parents:
19035
diff
changeset
|
1321 .client = TRUE, |
8f8f768937f5
http-client: Added support for using an HTTP proxy running on a unix socket.
Stephan Bosch <stephan@rename-it.nl>
parents:
19035
diff
changeset
|
1322 .delayed_unix_client_connected_callback = TRUE |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1323 }; |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1324 |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1325 static const struct connection_vfuncs http_client_connection_vfuncs = { |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1326 .destroy = http_client_connection_destroy, |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1327 .input = http_client_connection_input, |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1328 .client_connected = http_client_connection_connected |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1329 }; |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1330 |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1331 struct connection_list * |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1332 http_client_connection_list_init(void) |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1333 { |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1334 return connection_list_init |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1335 (&http_client_connection_set, &http_client_connection_vfuncs); |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1336 } |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1337 |
16148
1bd5972eac0a
lib-http: Simplify error handling by delaying connect() failures.
Timo Sirainen <tss@iki.fi>
parents:
16145
diff
changeset
|
1338 static void |
1bd5972eac0a
lib-http: Simplify error handling by delaying connect() failures.
Timo Sirainen <tss@iki.fi>
parents:
16145
diff
changeset
|
1339 http_client_connection_delayed_connect_error(struct http_client_connection *conn) |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1340 { |
16148
1bd5972eac0a
lib-http: Simplify error handling by delaying connect() failures.
Timo Sirainen <tss@iki.fi>
parents:
16145
diff
changeset
|
1341 timeout_remove(&conn->to_input); |
1bd5972eac0a
lib-http: Simplify error handling by delaying connect() failures.
Timo Sirainen <tss@iki.fi>
parents:
16145
diff
changeset
|
1342 errno = conn->connect_errno; |
1bd5972eac0a
lib-http: Simplify error handling by delaying connect() failures.
Timo Sirainen <tss@iki.fi>
parents:
16145
diff
changeset
|
1343 http_client_connection_connected(&conn->conn, FALSE); |
17968
c5f81685571f
lib-http: client: Fixed handling of connection timeouts.
Stephan Bosch <stephan@rename-it.nl>
parents:
17941
diff
changeset
|
1344 http_client_connection_close(&conn); |
16148
1bd5972eac0a
lib-http: Simplify error handling by delaying connect() failures.
Timo Sirainen <tss@iki.fi>
parents:
16145
diff
changeset
|
1345 } |
1bd5972eac0a
lib-http: Simplify error handling by delaying connect() failures.
Timo Sirainen <tss@iki.fi>
parents:
16145
diff
changeset
|
1346 |
16451
a551409911f9
lib-http: Added connect and request timeout settings.
Timo Sirainen <tss@iki.fi>
parents:
16450
diff
changeset
|
1347 static void http_client_connect_timeout(struct http_client_connection *conn) |
a551409911f9
lib-http: Added connect and request timeout settings.
Timo Sirainen <tss@iki.fi>
parents:
16450
diff
changeset
|
1348 { |
a551409911f9
lib-http: Added connect and request timeout settings.
Timo Sirainen <tss@iki.fi>
parents:
16450
diff
changeset
|
1349 conn->conn.disconnect_reason = CONNECTION_DISCONNECT_CONNECT_TIMEOUT; |
a551409911f9
lib-http: Added connect and request timeout settings.
Timo Sirainen <tss@iki.fi>
parents:
16450
diff
changeset
|
1350 http_client_connection_destroy(&conn->conn); |
a551409911f9
lib-http: Added connect and request timeout settings.
Timo Sirainen <tss@iki.fi>
parents:
16450
diff
changeset
|
1351 } |
a551409911f9
lib-http: Added connect and request timeout settings.
Timo Sirainen <tss@iki.fi>
parents:
16450
diff
changeset
|
1352 |
16856
b9498573f0d0
lib-http: http-client: Added support for tunneling SSL conntections through proxy.
Stephan Bosch <stephan@rename-it.nl>
parents:
16855
diff
changeset
|
1353 static void |
b9498573f0d0
lib-http: http-client: Added support for tunneling SSL conntections through proxy.
Stephan Bosch <stephan@rename-it.nl>
parents:
16855
diff
changeset
|
1354 http_client_connection_connect(struct http_client_connection *conn) |
16148
1bd5972eac0a
lib-http: Simplify error handling by delaying connect() failures.
Timo Sirainen <tss@iki.fi>
parents:
16145
diff
changeset
|
1355 { |
16451
a551409911f9
lib-http: Added connect and request timeout settings.
Timo Sirainen <tss@iki.fi>
parents:
16450
diff
changeset
|
1356 unsigned int msecs; |
a551409911f9
lib-http: Added connect and request timeout settings.
Timo Sirainen <tss@iki.fi>
parents:
16450
diff
changeset
|
1357 |
a551409911f9
lib-http: Added connect and request timeout settings.
Timo Sirainen <tss@iki.fi>
parents:
16450
diff
changeset
|
1358 conn->connect_start_timestamp = ioloop_timeval; |
16148
1bd5972eac0a
lib-http: Simplify error handling by delaying connect() failures.
Timo Sirainen <tss@iki.fi>
parents:
16145
diff
changeset
|
1359 if (connection_client_connect(&conn->conn) < 0) { |
1bd5972eac0a
lib-http: Simplify error handling by delaying connect() failures.
Timo Sirainen <tss@iki.fi>
parents:
16145
diff
changeset
|
1360 conn->connect_errno = errno; |
16574
a6b00756ab2c
lib-http: Added more debug messages.
Timo Sirainen <tss@iki.fi>
parents:
16572
diff
changeset
|
1361 http_client_connection_debug(conn, "Connect failed: %m"); |
16148
1bd5972eac0a
lib-http: Simplify error handling by delaying connect() failures.
Timo Sirainen <tss@iki.fi>
parents:
16145
diff
changeset
|
1362 conn->to_input = timeout_add_short(0, |
1bd5972eac0a
lib-http: Simplify error handling by delaying connect() failures.
Timo Sirainen <tss@iki.fi>
parents:
16145
diff
changeset
|
1363 http_client_connection_delayed_connect_error, conn); |
16451
a551409911f9
lib-http: Added connect and request timeout settings.
Timo Sirainen <tss@iki.fi>
parents:
16450
diff
changeset
|
1364 return; |
a551409911f9
lib-http: Added connect and request timeout settings.
Timo Sirainen <tss@iki.fi>
parents:
16450
diff
changeset
|
1365 } |
a551409911f9
lib-http: Added connect and request timeout settings.
Timo Sirainen <tss@iki.fi>
parents:
16450
diff
changeset
|
1366 |
a551409911f9
lib-http: Added connect and request timeout settings.
Timo Sirainen <tss@iki.fi>
parents:
16450
diff
changeset
|
1367 /* don't use connection.h timeout because we want this timeout |
a551409911f9
lib-http: Added connect and request timeout settings.
Timo Sirainen <tss@iki.fi>
parents:
16450
diff
changeset
|
1368 to include also the SSL handshake */ |
a551409911f9
lib-http: Added connect and request timeout settings.
Timo Sirainen <tss@iki.fi>
parents:
16450
diff
changeset
|
1369 msecs = conn->client->set.connect_timeout_msecs; |
a551409911f9
lib-http: Added connect and request timeout settings.
Timo Sirainen <tss@iki.fi>
parents:
16450
diff
changeset
|
1370 if (msecs == 0) |
a551409911f9
lib-http: Added connect and request timeout settings.
Timo Sirainen <tss@iki.fi>
parents:
16450
diff
changeset
|
1371 msecs = conn->client->set.request_timeout_msecs; |
a551409911f9
lib-http: Added connect and request timeout settings.
Timo Sirainen <tss@iki.fi>
parents:
16450
diff
changeset
|
1372 if (msecs > 0) { |
a551409911f9
lib-http: Added connect and request timeout settings.
Timo Sirainen <tss@iki.fi>
parents:
16450
diff
changeset
|
1373 conn->to_connect = |
a551409911f9
lib-http: Added connect and request timeout settings.
Timo Sirainen <tss@iki.fi>
parents:
16450
diff
changeset
|
1374 timeout_add(msecs, http_client_connect_timeout, conn); |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1375 } |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1376 } |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1377 |
16856
b9498573f0d0
lib-http: http-client: Added support for tunneling SSL conntections through proxy.
Stephan Bosch <stephan@rename-it.nl>
parents:
16855
diff
changeset
|
1378 static void |
b9498573f0d0
lib-http: http-client: Added support for tunneling SSL conntections through proxy.
Stephan Bosch <stephan@rename-it.nl>
parents:
16855
diff
changeset
|
1379 http_client_connect_tunnel_timeout(struct http_client_connection *conn) |
b9498573f0d0
lib-http: http-client: Added support for tunneling SSL conntections through proxy.
Stephan Bosch <stephan@rename-it.nl>
parents:
16855
diff
changeset
|
1380 { |
17987
43728039836c
lib-http: client: Fixed proxied client connect timeout.
Stephan Bosch <stephan@rename-it.nl>
parents:
17984
diff
changeset
|
1381 const char *error, *name = http_client_peer_addr2str(&conn->peer->addr); |
43728039836c
lib-http: client: Fixed proxied client connect timeout.
Stephan Bosch <stephan@rename-it.nl>
parents:
17984
diff
changeset
|
1382 unsigned int msecs; |
43728039836c
lib-http: client: Fixed proxied client connect timeout.
Stephan Bosch <stephan@rename-it.nl>
parents:
17984
diff
changeset
|
1383 |
43728039836c
lib-http: client: Fixed proxied client connect timeout.
Stephan Bosch <stephan@rename-it.nl>
parents:
17984
diff
changeset
|
1384 msecs = timeval_diff_msecs(&ioloop_timeval, |
43728039836c
lib-http: client: Fixed proxied client connect timeout.
Stephan Bosch <stephan@rename-it.nl>
parents:
17984
diff
changeset
|
1385 &conn->connect_start_timestamp); |
43728039836c
lib-http: client: Fixed proxied client connect timeout.
Stephan Bosch <stephan@rename-it.nl>
parents:
17984
diff
changeset
|
1386 error = t_strdup_printf( |
43728039836c
lib-http: client: Fixed proxied client connect timeout.
Stephan Bosch <stephan@rename-it.nl>
parents:
17984
diff
changeset
|
1387 "Tunnel connect(%s) failed: " |
43728039836c
lib-http: client: Fixed proxied client connect timeout.
Stephan Bosch <stephan@rename-it.nl>
parents:
17984
diff
changeset
|
1388 "Connection timed out in %u.%03u secs", |
43728039836c
lib-http: client: Fixed proxied client connect timeout.
Stephan Bosch <stephan@rename-it.nl>
parents:
17984
diff
changeset
|
1389 name, msecs/1000, msecs%1000); |
43728039836c
lib-http: client: Fixed proxied client connect timeout.
Stephan Bosch <stephan@rename-it.nl>
parents:
17984
diff
changeset
|
1390 |
43728039836c
lib-http: client: Fixed proxied client connect timeout.
Stephan Bosch <stephan@rename-it.nl>
parents:
17984
diff
changeset
|
1391 http_client_connection_debug(conn, "%s", error); |
43728039836c
lib-http: client: Fixed proxied client connect timeout.
Stephan Bosch <stephan@rename-it.nl>
parents:
17984
diff
changeset
|
1392 http_client_peer_connection_failure(conn->peer, error); |
17968
c5f81685571f
lib-http: client: Fixed handling of connection timeouts.
Stephan Bosch <stephan@rename-it.nl>
parents:
17941
diff
changeset
|
1393 http_client_connection_close(&conn); |
16856
b9498573f0d0
lib-http: http-client: Added support for tunneling SSL conntections through proxy.
Stephan Bosch <stephan@rename-it.nl>
parents:
16855
diff
changeset
|
1394 } |
b9498573f0d0
lib-http: http-client: Added support for tunneling SSL conntections through proxy.
Stephan Bosch <stephan@rename-it.nl>
parents:
16855
diff
changeset
|
1395 |
b9498573f0d0
lib-http: http-client: Added support for tunneling SSL conntections through proxy.
Stephan Bosch <stephan@rename-it.nl>
parents:
16855
diff
changeset
|
1396 static void |
b9498573f0d0
lib-http: http-client: Added support for tunneling SSL conntections through proxy.
Stephan Bosch <stephan@rename-it.nl>
parents:
16855
diff
changeset
|
1397 http_client_connection_tunnel_response(const struct http_response *response, |
b9498573f0d0
lib-http: http-client: Added support for tunneling SSL conntections through proxy.
Stephan Bosch <stephan@rename-it.nl>
parents:
16855
diff
changeset
|
1398 struct http_client_connection *conn) |
b9498573f0d0
lib-http: http-client: Added support for tunneling SSL conntections through proxy.
Stephan Bosch <stephan@rename-it.nl>
parents:
16855
diff
changeset
|
1399 { |
b9498573f0d0
lib-http: http-client: Added support for tunneling SSL conntections through proxy.
Stephan Bosch <stephan@rename-it.nl>
parents:
16855
diff
changeset
|
1400 struct http_client_tunnel tunnel; |
b9498573f0d0
lib-http: http-client: Added support for tunneling SSL conntections through proxy.
Stephan Bosch <stephan@rename-it.nl>
parents:
16855
diff
changeset
|
1401 const char *name = http_client_peer_addr2str(&conn->peer->addr); |
21028
7a59b4ec1ede
lib-http: client: Set conn->connect_request to NULL immediately in http_client_connection_tunnel_response().
Stephan Bosch <stephan@dovecot.fi>
parents:
20951
diff
changeset
|
1402 struct http_client_request *req = conn->connect_request; |
7a59b4ec1ede
lib-http: client: Set conn->connect_request to NULL immediately in http_client_connection_tunnel_response().
Stephan Bosch <stephan@dovecot.fi>
parents:
20951
diff
changeset
|
1403 |
7a59b4ec1ede
lib-http: client: Set conn->connect_request to NULL immediately in http_client_connection_tunnel_response().
Stephan Bosch <stephan@dovecot.fi>
parents:
20951
diff
changeset
|
1404 conn->connect_request = NULL; |
16856
b9498573f0d0
lib-http: http-client: Added support for tunneling SSL conntections through proxy.
Stephan Bosch <stephan@rename-it.nl>
parents:
16855
diff
changeset
|
1405 |
b9498573f0d0
lib-http: http-client: Added support for tunneling SSL conntections through proxy.
Stephan Bosch <stephan@rename-it.nl>
parents:
16855
diff
changeset
|
1406 if (response->status != 200) { |
21029
a3a045122aa4
lib-http: client: Created http_client_connection_failure() handler.
Stephan Bosch <stephan@dovecot.fi>
parents:
21028
diff
changeset
|
1407 http_client_connection_failure(conn, t_strdup_printf( |
21788
fe1059ceaa1e
global: Use http_response_get_message() to log HTTP responses.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21425
diff
changeset
|
1408 "Tunnel connect(%s) failed: %s", name, |
fe1059ceaa1e
global: Use http_response_get_message() to log HTTP responses.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21425
diff
changeset
|
1409 http_response_get_message(response))); |
16856
b9498573f0d0
lib-http: http-client: Added support for tunneling SSL conntections through proxy.
Stephan Bosch <stephan@rename-it.nl>
parents:
16855
diff
changeset
|
1410 return; |
b9498573f0d0
lib-http: http-client: Added support for tunneling SSL conntections through proxy.
Stephan Bosch <stephan@rename-it.nl>
parents:
16855
diff
changeset
|
1411 } |
b9498573f0d0
lib-http: http-client: Added support for tunneling SSL conntections through proxy.
Stephan Bosch <stephan@rename-it.nl>
parents:
16855
diff
changeset
|
1412 |
21028
7a59b4ec1ede
lib-http: client: Set conn->connect_request to NULL immediately in http_client_connection_tunnel_response().
Stephan Bosch <stephan@dovecot.fi>
parents:
20951
diff
changeset
|
1413 http_client_request_start_tunnel(req, &tunnel); |
16856
b9498573f0d0
lib-http: http-client: Added support for tunneling SSL conntections through proxy.
Stephan Bosch <stephan@rename-it.nl>
parents:
16855
diff
changeset
|
1414 |
18096
8eaaff8e2c63
lib-http: client: Removed connection code that is already in src/lib/connection.c.
Stephan Bosch <stephan@rename-it.nl>
parents:
18040
diff
changeset
|
1415 connection_init_from_streams |
16856
b9498573f0d0
lib-http: http-client: Added support for tunneling SSL conntections through proxy.
Stephan Bosch <stephan@rename-it.nl>
parents:
16855
diff
changeset
|
1416 (conn->client->conn_list, &conn->conn, name, tunnel.input, tunnel.output); |
18494
63224afb8c02
lib-http: client: Fixed memory leak in CONNECT tunnel support.
Stephan Bosch <stephan@rename-it.nl>
parents:
18137
diff
changeset
|
1417 i_stream_unref(&tunnel.input); |
63224afb8c02
lib-http: client: Fixed memory leak in CONNECT tunnel support.
Stephan Bosch <stephan@rename-it.nl>
parents:
18137
diff
changeset
|
1418 o_stream_unref(&tunnel.output); |
17987
43728039836c
lib-http: client: Fixed proxied client connect timeout.
Stephan Bosch <stephan@rename-it.nl>
parents:
17984
diff
changeset
|
1419 conn->connect_initialized = TRUE; |
16856
b9498573f0d0
lib-http: http-client: Added support for tunneling SSL conntections through proxy.
Stephan Bosch <stephan@rename-it.nl>
parents:
16855
diff
changeset
|
1420 } |
b9498573f0d0
lib-http: http-client: Added support for tunneling SSL conntections through proxy.
Stephan Bosch <stephan@rename-it.nl>
parents:
16855
diff
changeset
|
1421 |
b9498573f0d0
lib-http: http-client: Added support for tunneling SSL conntections through proxy.
Stephan Bosch <stephan@rename-it.nl>
parents:
16855
diff
changeset
|
1422 static void |
b9498573f0d0
lib-http: http-client: Added support for tunneling SSL conntections through proxy.
Stephan Bosch <stephan@rename-it.nl>
parents:
16855
diff
changeset
|
1423 http_client_connection_connect_tunnel(struct http_client_connection *conn, |
19035
aabfe48db1cf
Changed type of internet port values to in_port_t everywhere.
Stephan Bosch <stephan@rename-it.nl>
parents:
19033
diff
changeset
|
1424 const struct ip_addr *ip, in_port_t port) |
16856
b9498573f0d0
lib-http: http-client: Added support for tunneling SSL conntections through proxy.
Stephan Bosch <stephan@rename-it.nl>
parents:
16855
diff
changeset
|
1425 { |
b9498573f0d0
lib-http: http-client: Added support for tunneling SSL conntections through proxy.
Stephan Bosch <stephan@rename-it.nl>
parents:
16855
diff
changeset
|
1426 unsigned int msecs; |
b9498573f0d0
lib-http: http-client: Added support for tunneling SSL conntections through proxy.
Stephan Bosch <stephan@rename-it.nl>
parents:
16855
diff
changeset
|
1427 |
b9498573f0d0
lib-http: http-client: Added support for tunneling SSL conntections through proxy.
Stephan Bosch <stephan@rename-it.nl>
parents:
16855
diff
changeset
|
1428 conn->connect_start_timestamp = ioloop_timeval; |
b9498573f0d0
lib-http: http-client: Added support for tunneling SSL conntections through proxy.
Stephan Bosch <stephan@rename-it.nl>
parents:
16855
diff
changeset
|
1429 |
b9498573f0d0
lib-http: http-client: Added support for tunneling SSL conntections through proxy.
Stephan Bosch <stephan@rename-it.nl>
parents:
16855
diff
changeset
|
1430 conn->connect_request = http_client_request_connect_ip |
b9498573f0d0
lib-http: http-client: Added support for tunneling SSL conntections through proxy.
Stephan Bosch <stephan@rename-it.nl>
parents:
16855
diff
changeset
|
1431 (conn->client, ip, port, http_client_connection_tunnel_response, conn); |
b9498573f0d0
lib-http: http-client: Added support for tunneling SSL conntections through proxy.
Stephan Bosch <stephan@rename-it.nl>
parents:
16855
diff
changeset
|
1432 http_client_request_set_urgent(conn->connect_request); |
b9498573f0d0
lib-http: http-client: Added support for tunneling SSL conntections through proxy.
Stephan Bosch <stephan@rename-it.nl>
parents:
16855
diff
changeset
|
1433 http_client_request_submit(conn->connect_request); |
b9498573f0d0
lib-http: http-client: Added support for tunneling SSL conntections through proxy.
Stephan Bosch <stephan@rename-it.nl>
parents:
16855
diff
changeset
|
1434 |
b9498573f0d0
lib-http: http-client: Added support for tunneling SSL conntections through proxy.
Stephan Bosch <stephan@rename-it.nl>
parents:
16855
diff
changeset
|
1435 /* don't use connection.h timeout because we want this timeout |
b9498573f0d0
lib-http: http-client: Added support for tunneling SSL conntections through proxy.
Stephan Bosch <stephan@rename-it.nl>
parents:
16855
diff
changeset
|
1436 to include also the SSL handshake */ |
b9498573f0d0
lib-http: http-client: Added support for tunneling SSL conntections through proxy.
Stephan Bosch <stephan@rename-it.nl>
parents:
16855
diff
changeset
|
1437 msecs = conn->client->set.connect_timeout_msecs; |
b9498573f0d0
lib-http: http-client: Added support for tunneling SSL conntections through proxy.
Stephan Bosch <stephan@rename-it.nl>
parents:
16855
diff
changeset
|
1438 if (msecs == 0) |
b9498573f0d0
lib-http: http-client: Added support for tunneling SSL conntections through proxy.
Stephan Bosch <stephan@rename-it.nl>
parents:
16855
diff
changeset
|
1439 msecs = conn->client->set.request_timeout_msecs; |
b9498573f0d0
lib-http: http-client: Added support for tunneling SSL conntections through proxy.
Stephan Bosch <stephan@rename-it.nl>
parents:
16855
diff
changeset
|
1440 if (msecs > 0) { |
b9498573f0d0
lib-http: http-client: Added support for tunneling SSL conntections through proxy.
Stephan Bosch <stephan@rename-it.nl>
parents:
16855
diff
changeset
|
1441 conn->to_connect = |
b9498573f0d0
lib-http: http-client: Added support for tunneling SSL conntections through proxy.
Stephan Bosch <stephan@rename-it.nl>
parents:
16855
diff
changeset
|
1442 timeout_add(msecs, http_client_connect_tunnel_timeout, conn); |
b9498573f0d0
lib-http: http-client: Added support for tunneling SSL conntections through proxy.
Stephan Bosch <stephan@rename-it.nl>
parents:
16855
diff
changeset
|
1443 } |
b9498573f0d0
lib-http: http-client: Added support for tunneling SSL conntections through proxy.
Stephan Bosch <stephan@rename-it.nl>
parents:
16855
diff
changeset
|
1444 } |
b9498573f0d0
lib-http: http-client: Added support for tunneling SSL conntections through proxy.
Stephan Bosch <stephan@rename-it.nl>
parents:
16855
diff
changeset
|
1445 |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1446 struct http_client_connection * |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1447 http_client_connection_create(struct http_client_peer *peer) |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1448 { |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1449 struct http_client_connection *conn; |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1450 static unsigned int id = 0; |
16733
bdc5d6dcfc53
lib-http: http-client: Fixed request scheduling and connection management.
Stephan Bosch <stephan@rename-it.nl>
parents:
16731
diff
changeset
|
1451 const struct http_client_peer_addr *addr = &peer->addr; |
16855
c3884a6acde6
lib-http: Added support for creating CONNECT tunnels through HTTP.
Stephan Bosch <stephan@rename-it.nl>
parents:
16852
diff
changeset
|
1452 const char *conn_type = "UNKNOWN"; |
c3884a6acde6
lib-http: Added support for creating CONNECT tunnels through HTTP.
Stephan Bosch <stephan@rename-it.nl>
parents:
16852
diff
changeset
|
1453 |
c3884a6acde6
lib-http: Added support for creating CONNECT tunnels through HTTP.
Stephan Bosch <stephan@rename-it.nl>
parents:
16852
diff
changeset
|
1454 switch (peer->addr.type) { |
c3884a6acde6
lib-http: Added support for creating CONNECT tunnels through HTTP.
Stephan Bosch <stephan@rename-it.nl>
parents:
16852
diff
changeset
|
1455 case HTTP_CLIENT_PEER_ADDR_HTTP: |
c3884a6acde6
lib-http: Added support for creating CONNECT tunnels through HTTP.
Stephan Bosch <stephan@rename-it.nl>
parents:
16852
diff
changeset
|
1456 conn_type = "HTTP"; |
c3884a6acde6
lib-http: Added support for creating CONNECT tunnels through HTTP.
Stephan Bosch <stephan@rename-it.nl>
parents:
16852
diff
changeset
|
1457 break; |
c3884a6acde6
lib-http: Added support for creating CONNECT tunnels through HTTP.
Stephan Bosch <stephan@rename-it.nl>
parents:
16852
diff
changeset
|
1458 case HTTP_CLIENT_PEER_ADDR_HTTPS: |
c3884a6acde6
lib-http: Added support for creating CONNECT tunnels through HTTP.
Stephan Bosch <stephan@rename-it.nl>
parents:
16852
diff
changeset
|
1459 conn_type = "HTTPS"; |
c3884a6acde6
lib-http: Added support for creating CONNECT tunnels through HTTP.
Stephan Bosch <stephan@rename-it.nl>
parents:
16852
diff
changeset
|
1460 break; |
16856
b9498573f0d0
lib-http: http-client: Added support for tunneling SSL conntections through proxy.
Stephan Bosch <stephan@rename-it.nl>
parents:
16855
diff
changeset
|
1461 case HTTP_CLIENT_PEER_ADDR_HTTPS_TUNNEL: |
b9498573f0d0
lib-http: http-client: Added support for tunneling SSL conntections through proxy.
Stephan Bosch <stephan@rename-it.nl>
parents:
16855
diff
changeset
|
1462 conn_type = "Tunneled HTTPS"; |
b9498573f0d0
lib-http: http-client: Added support for tunneling SSL conntections through proxy.
Stephan Bosch <stephan@rename-it.nl>
parents:
16855
diff
changeset
|
1463 break; |
16855
c3884a6acde6
lib-http: Added support for creating CONNECT tunnels through HTTP.
Stephan Bosch <stephan@rename-it.nl>
parents:
16852
diff
changeset
|
1464 case HTTP_CLIENT_PEER_ADDR_RAW: |
c3884a6acde6
lib-http: Added support for creating CONNECT tunnels through HTTP.
Stephan Bosch <stephan@rename-it.nl>
parents:
16852
diff
changeset
|
1465 conn_type = "Raw"; |
c3884a6acde6
lib-http: Added support for creating CONNECT tunnels through HTTP.
Stephan Bosch <stephan@rename-it.nl>
parents:
16852
diff
changeset
|
1466 break; |
19039
8f8f768937f5
http-client: Added support for using an HTTP proxy running on a unix socket.
Stephan Bosch <stephan@rename-it.nl>
parents:
19035
diff
changeset
|
1467 case HTTP_CLIENT_PEER_ADDR_UNIX: |
8f8f768937f5
http-client: Added support for using an HTTP proxy running on a unix socket.
Stephan Bosch <stephan@rename-it.nl>
parents:
19035
diff
changeset
|
1468 conn_type = "Unix"; |
8f8f768937f5
http-client: Added support for using an HTTP proxy running on a unix socket.
Stephan Bosch <stephan@rename-it.nl>
parents:
19035
diff
changeset
|
1469 break; |
16855
c3884a6acde6
lib-http: Added support for creating CONNECT tunnels through HTTP.
Stephan Bosch <stephan@rename-it.nl>
parents:
16852
diff
changeset
|
1470 } |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1471 |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1472 conn = i_new(struct http_client_connection, 1); |
15710
c5230b8ffd40
lib-http: Various bugfixes
Stephan Bosch <stephan@rename-it.nl>
parents:
15579
diff
changeset
|
1473 conn->refcount = 1; |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1474 conn->client = peer->client; |
16733
bdc5d6dcfc53
lib-http: http-client: Fixed request scheduling and connection management.
Stephan Bosch <stephan@rename-it.nl>
parents:
16731
diff
changeset
|
1475 conn->id = id++; |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1476 conn->peer = peer; |
16855
c3884a6acde6
lib-http: Added support for creating CONNECT tunnels through HTTP.
Stephan Bosch <stephan@rename-it.nl>
parents:
16852
diff
changeset
|
1477 if (peer->addr.type != HTTP_CLIENT_PEER_ADDR_RAW) |
c3884a6acde6
lib-http: Added support for creating CONNECT tunnels through HTTP.
Stephan Bosch <stephan@rename-it.nl>
parents:
16852
diff
changeset
|
1478 i_array_init(&conn->request_wait_list, 16); |
21108
1a1310a5f7a8
lib-http: Use io_wait_timer for tracking wait times.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21042
diff
changeset
|
1479 conn->io_wait_timer = io_wait_timer_add(); |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1480 |
21040
9b04af4cbe62
lib-http: client: Improved labeling of debug messages.
Stephan Bosch <stephan@dovecot.fi>
parents:
21030
diff
changeset
|
1481 conn->label = i_strdup_printf("%s [%d]", |
9b04af4cbe62
lib-http: client: Improved labeling of debug messages.
Stephan Bosch <stephan@dovecot.fi>
parents:
21030
diff
changeset
|
1482 http_client_peer_label(peer), conn->id); |
9b04af4cbe62
lib-http: client: Improved labeling of debug messages.
Stephan Bosch <stephan@dovecot.fi>
parents:
21030
diff
changeset
|
1483 |
19039
8f8f768937f5
http-client: Added support for using an HTTP proxy running on a unix socket.
Stephan Bosch <stephan@rename-it.nl>
parents:
19035
diff
changeset
|
1484 switch (peer->addr.type) { |
8f8f768937f5
http-client: Added support for using an HTTP proxy running on a unix socket.
Stephan Bosch <stephan@rename-it.nl>
parents:
19035
diff
changeset
|
1485 case HTTP_CLIENT_PEER_ADDR_HTTPS_TUNNEL: |
8f8f768937f5
http-client: Added support for using an HTTP proxy running on a unix socket.
Stephan Bosch <stephan@rename-it.nl>
parents:
19035
diff
changeset
|
1486 http_client_connection_connect_tunnel |
8f8f768937f5
http-client: Added support for using an HTTP proxy running on a unix socket.
Stephan Bosch <stephan@rename-it.nl>
parents:
19035
diff
changeset
|
1487 (conn, &addr->a.tcp.ip, addr->a.tcp.port); |
8f8f768937f5
http-client: Added support for using an HTTP proxy running on a unix socket.
Stephan Bosch <stephan@rename-it.nl>
parents:
19035
diff
changeset
|
1488 break; |
8f8f768937f5
http-client: Added support for using an HTTP proxy running on a unix socket.
Stephan Bosch <stephan@rename-it.nl>
parents:
19035
diff
changeset
|
1489 case HTTP_CLIENT_PEER_ADDR_UNIX: |
8f8f768937f5
http-client: Added support for using an HTTP proxy running on a unix socket.
Stephan Bosch <stephan@rename-it.nl>
parents:
19035
diff
changeset
|
1490 connection_init_client_unix(peer->client->conn_list, &conn->conn, |
8f8f768937f5
http-client: Added support for using an HTTP proxy running on a unix socket.
Stephan Bosch <stephan@rename-it.nl>
parents:
19035
diff
changeset
|
1491 addr->a.un.path); |
8f8f768937f5
http-client: Added support for using an HTTP proxy running on a unix socket.
Stephan Bosch <stephan@rename-it.nl>
parents:
19035
diff
changeset
|
1492 conn->connect_initialized = TRUE; |
8f8f768937f5
http-client: Added support for using an HTTP proxy running on a unix socket.
Stephan Bosch <stephan@rename-it.nl>
parents:
19035
diff
changeset
|
1493 http_client_connection_connect(conn); |
8f8f768937f5
http-client: Added support for using an HTTP proxy running on a unix socket.
Stephan Bosch <stephan@rename-it.nl>
parents:
19035
diff
changeset
|
1494 break; |
8f8f768937f5
http-client: Added support for using an HTTP proxy running on a unix socket.
Stephan Bosch <stephan@rename-it.nl>
parents:
19035
diff
changeset
|
1495 default: |
8f8f768937f5
http-client: Added support for using an HTTP proxy running on a unix socket.
Stephan Bosch <stephan@rename-it.nl>
parents:
19035
diff
changeset
|
1496 connection_init_client_ip(peer->client->conn_list, &conn->conn, |
8f8f768937f5
http-client: Added support for using an HTTP proxy running on a unix socket.
Stephan Bosch <stephan@rename-it.nl>
parents:
19035
diff
changeset
|
1497 &addr->a.tcp.ip, addr->a.tcp.port); |
17987
43728039836c
lib-http: client: Fixed proxied client connect timeout.
Stephan Bosch <stephan@rename-it.nl>
parents:
17984
diff
changeset
|
1498 conn->connect_initialized = TRUE; |
16856
b9498573f0d0
lib-http: http-client: Added support for tunneling SSL conntections through proxy.
Stephan Bosch <stephan@rename-it.nl>
parents:
16855
diff
changeset
|
1499 http_client_connection_connect(conn); |
b9498573f0d0
lib-http: http-client: Added support for tunneling SSL conntections through proxy.
Stephan Bosch <stephan@rename-it.nl>
parents:
16855
diff
changeset
|
1500 } |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1501 |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1502 array_append(&peer->conns, &conn, 1); |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1503 |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1504 http_client_connection_debug(conn, |
16855
c3884a6acde6
lib-http: Added support for creating CONNECT tunnels through HTTP.
Stephan Bosch <stephan@rename-it.nl>
parents:
16852
diff
changeset
|
1505 "%s connection created (%d parallel connections exist)%s", |
c3884a6acde6
lib-http: Added support for creating CONNECT tunnels through HTTP.
Stephan Bosch <stephan@rename-it.nl>
parents:
16852
diff
changeset
|
1506 conn_type, array_count(&peer->conns), |
c3884a6acde6
lib-http: Added support for creating CONNECT tunnels through HTTP.
Stephan Bosch <stephan@rename-it.nl>
parents:
16852
diff
changeset
|
1507 (conn->to_input == NULL ? "" : " [broken]")); |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1508 return conn; |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1509 } |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1510 |
15710
c5230b8ffd40
lib-http: Various bugfixes
Stephan Bosch <stephan@rename-it.nl>
parents:
15579
diff
changeset
|
1511 void http_client_connection_ref(struct http_client_connection *conn) |
c5230b8ffd40
lib-http: Various bugfixes
Stephan Bosch <stephan@rename-it.nl>
parents:
15579
diff
changeset
|
1512 { |
19236
c30c30c1e642
lib-http: Added asserts to all refcount increments.
Timo Sirainen <tss@iki.fi>
parents:
19235
diff
changeset
|
1513 i_assert(conn->refcount > 0); |
15710
c5230b8ffd40
lib-http: Various bugfixes
Stephan Bosch <stephan@rename-it.nl>
parents:
15579
diff
changeset
|
1514 conn->refcount++; |
c5230b8ffd40
lib-http: Various bugfixes
Stephan Bosch <stephan@rename-it.nl>
parents:
15579
diff
changeset
|
1515 } |
c5230b8ffd40
lib-http: Various bugfixes
Stephan Bosch <stephan@rename-it.nl>
parents:
15579
diff
changeset
|
1516 |
17610
320a224ad353
lib-http: Made sure that connections that are still connecting to the server aren't marked as idle.
Stephan Bosch <stephan@rename-it.nl>
parents:
17549
diff
changeset
|
1517 static void |
320a224ad353
lib-http: Made sure that connections that are still connecting to the server aren't marked as idle.
Stephan Bosch <stephan@rename-it.nl>
parents:
17549
diff
changeset
|
1518 http_client_connection_disconnect(struct http_client_connection *conn) |
320a224ad353
lib-http: Made sure that connections that are still connecting to the server aren't marked as idle.
Stephan Bosch <stephan@rename-it.nl>
parents:
17549
diff
changeset
|
1519 { |
20354
adfa1b7fea65
lib-http: client: Reworked connection close handling.
Stephan Bosch <stephan@dovecot.fi>
parents:
20352
diff
changeset
|
1520 struct http_client_peer *peer = conn->peer; |
adfa1b7fea65
lib-http: client: Reworked connection close handling.
Stephan Bosch <stephan@dovecot.fi>
parents:
20352
diff
changeset
|
1521 ARRAY_TYPE(http_client_connection) *conn_arr; |
adfa1b7fea65
lib-http: client: Reworked connection close handling.
Stephan Bosch <stephan@dovecot.fi>
parents:
20352
diff
changeset
|
1522 struct http_client_connection *const *conn_idx; |
adfa1b7fea65
lib-http: client: Reworked connection close handling.
Stephan Bosch <stephan@dovecot.fi>
parents:
20352
diff
changeset
|
1523 |
adfa1b7fea65
lib-http: client: Reworked connection close handling.
Stephan Bosch <stephan@dovecot.fi>
parents:
20352
diff
changeset
|
1524 if (conn->disconnected) |
adfa1b7fea65
lib-http: client: Reworked connection close handling.
Stephan Bosch <stephan@dovecot.fi>
parents:
20352
diff
changeset
|
1525 return; |
adfa1b7fea65
lib-http: client: Reworked connection close handling.
Stephan Bosch <stephan@dovecot.fi>
parents:
20352
diff
changeset
|
1526 conn->disconnected = TRUE; |
adfa1b7fea65
lib-http: client: Reworked connection close handling.
Stephan Bosch <stephan@dovecot.fi>
parents:
20352
diff
changeset
|
1527 |
adfa1b7fea65
lib-http: client: Reworked connection close handling.
Stephan Bosch <stephan@dovecot.fi>
parents:
20352
diff
changeset
|
1528 http_client_connection_debug(conn, "Connection disconnect"); |
adfa1b7fea65
lib-http: client: Reworked connection close handling.
Stephan Bosch <stephan@dovecot.fi>
parents:
20352
diff
changeset
|
1529 |
17610
320a224ad353
lib-http: Made sure that connections that are still connecting to the server aren't marked as idle.
Stephan Bosch <stephan@rename-it.nl>
parents:
17549
diff
changeset
|
1530 conn->closing = TRUE; |
320a224ad353
lib-http: Made sure that connections that are still connecting to the server aren't marked as idle.
Stephan Bosch <stephan@rename-it.nl>
parents:
17549
diff
changeset
|
1531 conn->connected = FALSE; |
320a224ad353
lib-http: Made sure that connections that are still connecting to the server aren't marked as idle.
Stephan Bosch <stephan@rename-it.nl>
parents:
17549
diff
changeset
|
1532 |
320a224ad353
lib-http: Made sure that connections that are still connecting to the server aren't marked as idle.
Stephan Bosch <stephan@rename-it.nl>
parents:
17549
diff
changeset
|
1533 if (conn->connect_request != NULL) |
320a224ad353
lib-http: Made sure that connections that are still connecting to the server aren't marked as idle.
Stephan Bosch <stephan@rename-it.nl>
parents:
17549
diff
changeset
|
1534 http_client_request_abort(&conn->connect_request); |
320a224ad353
lib-http: Made sure that connections that are still connecting to the server aren't marked as idle.
Stephan Bosch <stephan@rename-it.nl>
parents:
17549
diff
changeset
|
1535 |
320a224ad353
lib-http: Made sure that connections that are still connecting to the server aren't marked as idle.
Stephan Bosch <stephan@rename-it.nl>
parents:
17549
diff
changeset
|
1536 if (conn->incoming_payload != NULL) { |
320a224ad353
lib-http: Made sure that connections that are still connecting to the server aren't marked as idle.
Stephan Bosch <stephan@rename-it.nl>
parents:
17549
diff
changeset
|
1537 /* the stream is still accessed by lib-http caller. */ |
320a224ad353
lib-http: Made sure that connections that are still connecting to the server aren't marked as idle.
Stephan Bosch <stephan@rename-it.nl>
parents:
17549
diff
changeset
|
1538 i_stream_remove_destroy_callback(conn->incoming_payload, |
320a224ad353
lib-http: Made sure that connections that are still connecting to the server aren't marked as idle.
Stephan Bosch <stephan@rename-it.nl>
parents:
17549
diff
changeset
|
1539 http_client_payload_destroyed); |
17846
475ff24ac365
lib-http: Fixed assert-crash when http_client_connection_disconnect() is called multiple times.
Timo Sirainen <tss@iki.fi>
parents:
17773
diff
changeset
|
1540 conn->incoming_payload = NULL; |
17610
320a224ad353
lib-http: Made sure that connections that are still connecting to the server aren't marked as idle.
Stephan Bosch <stephan@rename-it.nl>
parents:
17549
diff
changeset
|
1541 } |
320a224ad353
lib-http: Made sure that connections that are still connecting to the server aren't marked as idle.
Stephan Bosch <stephan@rename-it.nl>
parents:
17549
diff
changeset
|
1542 |
19726
f40f5e721744
lib-http: client: Make sure that any pending request is aborted and destroyed before connection FDs are closed.
Stephan Bosch <stephan@rename-it.nl>
parents:
19552
diff
changeset
|
1543 http_client_connection_abort_any_requests(conn); |
f40f5e721744
lib-http: client: Make sure that any pending request is aborted and destroyed before connection FDs are closed.
Stephan Bosch <stephan@rename-it.nl>
parents:
19552
diff
changeset
|
1544 |
f40f5e721744
lib-http: client: Make sure that any pending request is aborted and destroyed before connection FDs are closed.
Stephan Bosch <stephan@rename-it.nl>
parents:
19552
diff
changeset
|
1545 if (conn->http_parser != NULL) |
f40f5e721744
lib-http: client: Make sure that any pending request is aborted and destroyed before connection FDs are closed.
Stephan Bosch <stephan@rename-it.nl>
parents:
19552
diff
changeset
|
1546 http_response_parser_deinit(&conn->http_parser); |
f40f5e721744
lib-http: client: Make sure that any pending request is aborted and destroyed before connection FDs are closed.
Stephan Bosch <stephan@rename-it.nl>
parents:
19552
diff
changeset
|
1547 |
17987
43728039836c
lib-http: client: Fixed proxied client connect timeout.
Stephan Bosch <stephan@rename-it.nl>
parents:
17984
diff
changeset
|
1548 if (conn->connect_initialized) |
43728039836c
lib-http: client: Fixed proxied client connect timeout.
Stephan Bosch <stephan@rename-it.nl>
parents:
17984
diff
changeset
|
1549 connection_disconnect(&conn->conn); |
17610
320a224ad353
lib-http: Made sure that connections that are still connecting to the server aren't marked as idle.
Stephan Bosch <stephan@rename-it.nl>
parents:
17549
diff
changeset
|
1550 |
320a224ad353
lib-http: Made sure that connections that are still connecting to the server aren't marked as idle.
Stephan Bosch <stephan@rename-it.nl>
parents:
17549
diff
changeset
|
1551 if (conn->io_req_payload != NULL) |
320a224ad353
lib-http: Made sure that connections that are still connecting to the server aren't marked as idle.
Stephan Bosch <stephan@rename-it.nl>
parents:
17549
diff
changeset
|
1552 io_remove(&conn->io_req_payload); |
320a224ad353
lib-http: Made sure that connections that are still connecting to the server aren't marked as idle.
Stephan Bosch <stephan@rename-it.nl>
parents:
17549
diff
changeset
|
1553 if (conn->to_requests != NULL) |
320a224ad353
lib-http: Made sure that connections that are still connecting to the server aren't marked as idle.
Stephan Bosch <stephan@rename-it.nl>
parents:
17549
diff
changeset
|
1554 timeout_remove(&conn->to_requests); |
320a224ad353
lib-http: Made sure that connections that are still connecting to the server aren't marked as idle.
Stephan Bosch <stephan@rename-it.nl>
parents:
17549
diff
changeset
|
1555 if (conn->to_connect != NULL) |
320a224ad353
lib-http: Made sure that connections that are still connecting to the server aren't marked as idle.
Stephan Bosch <stephan@rename-it.nl>
parents:
17549
diff
changeset
|
1556 timeout_remove(&conn->to_connect); |
320a224ad353
lib-http: Made sure that connections that are still connecting to the server aren't marked as idle.
Stephan Bosch <stephan@rename-it.nl>
parents:
17549
diff
changeset
|
1557 if (conn->to_input != NULL) |
320a224ad353
lib-http: Made sure that connections that are still connecting to the server aren't marked as idle.
Stephan Bosch <stephan@rename-it.nl>
parents:
17549
diff
changeset
|
1558 timeout_remove(&conn->to_input); |
320a224ad353
lib-http: Made sure that connections that are still connecting to the server aren't marked as idle.
Stephan Bosch <stephan@rename-it.nl>
parents:
17549
diff
changeset
|
1559 if (conn->to_idle != NULL) |
320a224ad353
lib-http: Made sure that connections that are still connecting to the server aren't marked as idle.
Stephan Bosch <stephan@rename-it.nl>
parents:
17549
diff
changeset
|
1560 timeout_remove(&conn->to_idle); |
320a224ad353
lib-http: Made sure that connections that are still connecting to the server aren't marked as idle.
Stephan Bosch <stephan@rename-it.nl>
parents:
17549
diff
changeset
|
1561 if (conn->to_response != NULL) |
320a224ad353
lib-http: Made sure that connections that are still connecting to the server aren't marked as idle.
Stephan Bosch <stephan@rename-it.nl>
parents:
17549
diff
changeset
|
1562 timeout_remove(&conn->to_response); |
20354
adfa1b7fea65
lib-http: client: Reworked connection close handling.
Stephan Bosch <stephan@dovecot.fi>
parents:
20352
diff
changeset
|
1563 |
adfa1b7fea65
lib-http: client: Reworked connection close handling.
Stephan Bosch <stephan@dovecot.fi>
parents:
20352
diff
changeset
|
1564 /* remove this connection from the list */ |
adfa1b7fea65
lib-http: client: Reworked connection close handling.
Stephan Bosch <stephan@dovecot.fi>
parents:
20352
diff
changeset
|
1565 conn_arr = &peer->conns; |
adfa1b7fea65
lib-http: client: Reworked connection close handling.
Stephan Bosch <stephan@dovecot.fi>
parents:
20352
diff
changeset
|
1566 array_foreach(conn_arr, conn_idx) { |
adfa1b7fea65
lib-http: client: Reworked connection close handling.
Stephan Bosch <stephan@dovecot.fi>
parents:
20352
diff
changeset
|
1567 if (*conn_idx == conn) { |
adfa1b7fea65
lib-http: client: Reworked connection close handling.
Stephan Bosch <stephan@dovecot.fi>
parents:
20352
diff
changeset
|
1568 array_delete(conn_arr, array_foreach_idx(conn_arr, conn_idx), 1); |
adfa1b7fea65
lib-http: client: Reworked connection close handling.
Stephan Bosch <stephan@dovecot.fi>
parents:
20352
diff
changeset
|
1569 break; |
adfa1b7fea65
lib-http: client: Reworked connection close handling.
Stephan Bosch <stephan@dovecot.fi>
parents:
20352
diff
changeset
|
1570 } |
adfa1b7fea65
lib-http: client: Reworked connection close handling.
Stephan Bosch <stephan@dovecot.fi>
parents:
20352
diff
changeset
|
1571 } |
adfa1b7fea65
lib-http: client: Reworked connection close handling.
Stephan Bosch <stephan@dovecot.fi>
parents:
20352
diff
changeset
|
1572 |
adfa1b7fea65
lib-http: client: Reworked connection close handling.
Stephan Bosch <stephan@dovecot.fi>
parents:
20352
diff
changeset
|
1573 if (conn->connect_succeeded) |
21334
919df3038bf5
lib-http: client: Treat connections that get disconnected prematurely as connection failures.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21333
diff
changeset
|
1574 http_client_peer_connection_lost(peer, conn->lost_prematurely); |
17610
320a224ad353
lib-http: Made sure that connections that are still connecting to the server aren't marked as idle.
Stephan Bosch <stephan@rename-it.nl>
parents:
17549
diff
changeset
|
1575 } |
320a224ad353
lib-http: Made sure that connections that are still connecting to the server aren't marked as idle.
Stephan Bosch <stephan@rename-it.nl>
parents:
17549
diff
changeset
|
1576 |
19816
e2f9c117aef7
lib-http: http_client_connection_unref() now always sets *conn=NULL
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19727
diff
changeset
|
1577 bool http_client_connection_unref(struct http_client_connection **_conn) |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1578 { |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1579 struct http_client_connection *conn = *_conn; |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1580 |
15710
c5230b8ffd40
lib-http: Various bugfixes
Stephan Bosch <stephan@rename-it.nl>
parents:
15579
diff
changeset
|
1581 i_assert(conn->refcount > 0); |
c5230b8ffd40
lib-http: Various bugfixes
Stephan Bosch <stephan@rename-it.nl>
parents:
15579
diff
changeset
|
1582 |
19816
e2f9c117aef7
lib-http: http_client_connection_unref() now always sets *conn=NULL
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19727
diff
changeset
|
1583 *_conn = NULL; |
e2f9c117aef7
lib-http: http_client_connection_unref() now always sets *conn=NULL
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19727
diff
changeset
|
1584 |
15710
c5230b8ffd40
lib-http: Various bugfixes
Stephan Bosch <stephan@rename-it.nl>
parents:
15579
diff
changeset
|
1585 if (--conn->refcount > 0) |
19816
e2f9c117aef7
lib-http: http_client_connection_unref() now always sets *conn=NULL
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19727
diff
changeset
|
1586 return TRUE; |
15710
c5230b8ffd40
lib-http: Various bugfixes
Stephan Bosch <stephan@rename-it.nl>
parents:
15579
diff
changeset
|
1587 |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1588 http_client_connection_debug(conn, "Connection destroy"); |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1589 |
17610
320a224ad353
lib-http: Made sure that connections that are still connecting to the server aren't marked as idle.
Stephan Bosch <stephan@rename-it.nl>
parents:
17549
diff
changeset
|
1590 http_client_connection_disconnect(conn); |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1591 |
20354
adfa1b7fea65
lib-http: client: Reworked connection close handling.
Stephan Bosch <stephan@dovecot.fi>
parents:
20352
diff
changeset
|
1592 i_assert(conn->io_req_payload == NULL); |
adfa1b7fea65
lib-http: client: Reworked connection close handling.
Stephan Bosch <stephan@dovecot.fi>
parents:
20352
diff
changeset
|
1593 i_assert(conn->to_requests == NULL); |
adfa1b7fea65
lib-http: client: Reworked connection close handling.
Stephan Bosch <stephan@dovecot.fi>
parents:
20352
diff
changeset
|
1594 i_assert(conn->to_connect == NULL); |
adfa1b7fea65
lib-http: client: Reworked connection close handling.
Stephan Bosch <stephan@dovecot.fi>
parents:
20352
diff
changeset
|
1595 i_assert(conn->to_input == NULL); |
adfa1b7fea65
lib-http: client: Reworked connection close handling.
Stephan Bosch <stephan@dovecot.fi>
parents:
20352
diff
changeset
|
1596 i_assert(conn->to_idle == NULL); |
adfa1b7fea65
lib-http: client: Reworked connection close handling.
Stephan Bosch <stephan@dovecot.fi>
parents:
20352
diff
changeset
|
1597 i_assert(conn->to_response == NULL); |
adfa1b7fea65
lib-http: client: Reworked connection close handling.
Stephan Bosch <stephan@dovecot.fi>
parents:
20352
diff
changeset
|
1598 |
19726
f40f5e721744
lib-http: client: Make sure that any pending request is aborted and destroyed before connection FDs are closed.
Stephan Bosch <stephan@rename-it.nl>
parents:
19552
diff
changeset
|
1599 if (array_is_created(&conn->request_wait_list)) |
16855
c3884a6acde6
lib-http: Added support for creating CONNECT tunnels through HTTP.
Stephan Bosch <stephan@rename-it.nl>
parents:
16852
diff
changeset
|
1600 array_free(&conn->request_wait_list); |
16152
998afe8ffed9
lib-http: Reorder http_client_connection deinit code just to be safe.
Timo Sirainen <tss@iki.fi>
parents:
16151
diff
changeset
|
1601 |
998afe8ffed9
lib-http: Reorder http_client_connection deinit code just to be safe.
Timo Sirainen <tss@iki.fi>
parents:
16151
diff
changeset
|
1602 if (conn->ssl_iostream != NULL) |
998afe8ffed9
lib-http: Reorder http_client_connection deinit code just to be safe.
Timo Sirainen <tss@iki.fi>
parents:
16151
diff
changeset
|
1603 ssl_iostream_unref(&conn->ssl_iostream); |
17987
43728039836c
lib-http: client: Fixed proxied client connect timeout.
Stephan Bosch <stephan@rename-it.nl>
parents:
17984
diff
changeset
|
1604 if (conn->connect_initialized) |
43728039836c
lib-http: client: Fixed proxied client connect timeout.
Stephan Bosch <stephan@rename-it.nl>
parents:
17984
diff
changeset
|
1605 connection_deinit(&conn->conn); |
21108
1a1310a5f7a8
lib-http: Use io_wait_timer for tracking wait times.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21042
diff
changeset
|
1606 io_wait_timer_remove(&conn->io_wait_timer); |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1607 |
22247
60ecab5c8e9e
lib-http: Fix memory leak in HTTP connection deinit
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22213
diff
changeset
|
1608 i_free(conn->label); |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1609 i_free(conn); |
19816
e2f9c117aef7
lib-http: http_client_connection_unref() now always sets *conn=NULL
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19727
diff
changeset
|
1610 return FALSE; |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1611 } |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1612 |
17968
c5f81685571f
lib-http: client: Fixed handling of connection timeouts.
Stephan Bosch <stephan@rename-it.nl>
parents:
17941
diff
changeset
|
1613 void http_client_connection_close(struct http_client_connection **_conn) |
c5f81685571f
lib-http: client: Fixed handling of connection timeouts.
Stephan Bosch <stephan@rename-it.nl>
parents:
17941
diff
changeset
|
1614 { |
c5f81685571f
lib-http: client: Fixed handling of connection timeouts.
Stephan Bosch <stephan@rename-it.nl>
parents:
17941
diff
changeset
|
1615 struct http_client_connection *conn = *_conn; |
c5f81685571f
lib-http: client: Fixed handling of connection timeouts.
Stephan Bosch <stephan@rename-it.nl>
parents:
17941
diff
changeset
|
1616 |
c5f81685571f
lib-http: client: Fixed handling of connection timeouts.
Stephan Bosch <stephan@rename-it.nl>
parents:
17941
diff
changeset
|
1617 http_client_connection_debug(conn, "Connection close"); |
c5f81685571f
lib-http: client: Fixed handling of connection timeouts.
Stephan Bosch <stephan@rename-it.nl>
parents:
17941
diff
changeset
|
1618 |
c5f81685571f
lib-http: client: Fixed handling of connection timeouts.
Stephan Bosch <stephan@rename-it.nl>
parents:
17941
diff
changeset
|
1619 http_client_connection_disconnect(conn); |
c5f81685571f
lib-http: client: Fixed handling of connection timeouts.
Stephan Bosch <stephan@rename-it.nl>
parents:
17941
diff
changeset
|
1620 |
c5f81685571f
lib-http: client: Fixed handling of connection timeouts.
Stephan Bosch <stephan@rename-it.nl>
parents:
17941
diff
changeset
|
1621 http_client_connection_unref(_conn); |
c5f81685571f
lib-http: client: Fixed handling of connection timeouts.
Stephan Bosch <stephan@rename-it.nl>
parents:
17941
diff
changeset
|
1622 } |
c5f81685571f
lib-http: client: Fixed handling of connection timeouts.
Stephan Bosch <stephan@rename-it.nl>
parents:
17941
diff
changeset
|
1623 |
20354
adfa1b7fea65
lib-http: client: Reworked connection close handling.
Stephan Bosch <stephan@dovecot.fi>
parents:
20352
diff
changeset
|
1624 void http_client_connection_peer_closed(struct http_client_connection **_conn) |
adfa1b7fea65
lib-http: client: Reworked connection close handling.
Stephan Bosch <stephan@dovecot.fi>
parents:
20352
diff
changeset
|
1625 { |
adfa1b7fea65
lib-http: client: Reworked connection close handling.
Stephan Bosch <stephan@dovecot.fi>
parents:
20352
diff
changeset
|
1626 struct http_client_connection *conn = *_conn; |
adfa1b7fea65
lib-http: client: Reworked connection close handling.
Stephan Bosch <stephan@dovecot.fi>
parents:
20352
diff
changeset
|
1627 |
adfa1b7fea65
lib-http: client: Reworked connection close handling.
Stephan Bosch <stephan@dovecot.fi>
parents:
20352
diff
changeset
|
1628 http_client_connection_debug(conn, "Peer closed"); |
adfa1b7fea65
lib-http: client: Reworked connection close handling.
Stephan Bosch <stephan@dovecot.fi>
parents:
20352
diff
changeset
|
1629 http_client_connection_disconnect(conn); |
adfa1b7fea65
lib-http: client: Reworked connection close handling.
Stephan Bosch <stephan@dovecot.fi>
parents:
20352
diff
changeset
|
1630 |
adfa1b7fea65
lib-http: client: Reworked connection close handling.
Stephan Bosch <stephan@dovecot.fi>
parents:
20352
diff
changeset
|
1631 if (http_client_connection_unref(_conn)) |
adfa1b7fea65
lib-http: client: Reworked connection close handling.
Stephan Bosch <stephan@dovecot.fi>
parents:
20352
diff
changeset
|
1632 conn->peer = NULL; |
adfa1b7fea65
lib-http: client: Reworked connection close handling.
Stephan Bosch <stephan@dovecot.fi>
parents:
20352
diff
changeset
|
1633 } |
adfa1b7fea65
lib-http: client: Reworked connection close handling.
Stephan Bosch <stephan@dovecot.fi>
parents:
20352
diff
changeset
|
1634 |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1635 void http_client_connection_switch_ioloop(struct http_client_connection *conn) |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1636 { |
16739
a6ed95a30cb1
lib-http: Added support for asynchronous payload for requests.
Stephan Bosch <stephan@rename-it.nl>
parents:
16733
diff
changeset
|
1637 if (conn->io_req_payload != NULL) |
a6ed95a30cb1
lib-http: Added support for asynchronous payload for requests.
Stephan Bosch <stephan@rename-it.nl>
parents:
16733
diff
changeset
|
1638 conn->io_req_payload = io_loop_move_io(&conn->io_req_payload); |
16451
a551409911f9
lib-http: Added connect and request timeout settings.
Timo Sirainen <tss@iki.fi>
parents:
16450
diff
changeset
|
1639 if (conn->to_requests != NULL) |
a551409911f9
lib-http: Added connect and request timeout settings.
Timo Sirainen <tss@iki.fi>
parents:
16450
diff
changeset
|
1640 conn->to_requests = io_loop_move_timeout(&conn->to_requests); |
a551409911f9
lib-http: Added connect and request timeout settings.
Timo Sirainen <tss@iki.fi>
parents:
16450
diff
changeset
|
1641 if (conn->to_connect != NULL) |
16567
975fdf5a6987
lib-http: Timeouts were being handled wrong/leaked by ioloop switching.
Timo Sirainen <tss@iki.fi>
parents:
16566
diff
changeset
|
1642 conn->to_connect = io_loop_move_timeout(&conn->to_connect); |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1643 if (conn->to_input != NULL) |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1644 conn->to_input = io_loop_move_timeout(&conn->to_input); |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1645 if (conn->to_idle != NULL) |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1646 conn->to_idle = io_loop_move_timeout(&conn->to_idle); |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1647 if (conn->to_response != NULL) |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1648 conn->to_response = io_loop_move_timeout(&conn->to_response); |
17191
790afcf05f0d
lib-http: Wrap response payload istream into a istream-timeout.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
1649 if (conn->incoming_payload != NULL) |
790afcf05f0d
lib-http: Wrap response payload istream into a istream-timeout.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
1650 i_stream_switch_ioloop(conn->incoming_payload); |
21108
1a1310a5f7a8
lib-http: Use io_wait_timer for tracking wait times.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21042
diff
changeset
|
1651 conn->io_wait_timer = io_wait_timer_move(&conn->io_wait_timer); |
15394
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1652 connection_switch_ioloop(&conn->conn); |
107c8b2c9594
lib-http: Added initial HTTP client implementation.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff
changeset
|
1653 } |