Add first steps to honor timeout from server as proxy
This commit is contained in:
@ -352,6 +352,7 @@ static int proxy_connect(proxy_ctx_t *proxy, host_config_t *conf, http_res *res,
|
|||||||
proxy->initialized = 1;
|
proxy->initialized = 1;
|
||||||
proxy->cnx_s = clock_micros();
|
proxy->cnx_s = clock_micros();
|
||||||
proxy->host = conf->name;
|
proxy->host = conf->name;
|
||||||
|
proxy->timeout = 0;
|
||||||
|
|
||||||
info(BLUE_STR "Established new connection with " BLD_STR "[%s]:%i", addr_buf, conf->proxy.port);
|
info(BLUE_STR "Established new connection with " BLD_STR "[%s]:%i", addr_buf, conf->proxy.port);
|
||||||
|
|
||||||
@ -370,7 +371,9 @@ int proxy_init(proxy_ctx_t **proxy_ptr, http_req *req, http_res *res, http_statu
|
|||||||
while (retry) {
|
while (retry) {
|
||||||
errno = 0;
|
errno = 0;
|
||||||
|
|
||||||
if (!proxy->initialized || sock_has_pending(&proxy->proxy) != 0) {
|
if (!proxy->initialized || sock_has_pending(&proxy->proxy) != 0 ||
|
||||||
|
(proxy->timeout != 0 && (clock_micros() - proxy->proxy.ts_last) > proxy->timeout))
|
||||||
|
{
|
||||||
if (proxy->initialized)
|
if (proxy->initialized)
|
||||||
proxy_close(proxy);
|
proxy_close(proxy);
|
||||||
|
|
||||||
@ -533,6 +536,8 @@ int proxy_init(proxy_ctx_t **proxy_ptr, http_req *req, http_res *res, http_statu
|
|||||||
}
|
}
|
||||||
sock_recv_x(&proxy->proxy, buffer, header_len, 0);
|
sock_recv_x(&proxy->proxy, buffer, header_len, 0);
|
||||||
|
|
||||||
|
// TODO read timeout from Keep-Alive
|
||||||
|
|
||||||
ret = proxy_response_header(req, res, conf);
|
ret = proxy_response_header(req, res, conf);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
res->status = http_get_status(500);
|
res->status = http_get_status(500);
|
||||||
|
@ -22,6 +22,7 @@ typedef struct {
|
|||||||
unsigned char initialized:1, in_use:1;
|
unsigned char initialized:1, in_use:1;
|
||||||
sock proxy;
|
sock proxy;
|
||||||
long cnx_s, cnx_e;
|
long cnx_s, cnx_e;
|
||||||
|
long timeout;
|
||||||
char *host;
|
char *host;
|
||||||
void *client;
|
void *client;
|
||||||
} proxy_ctx_t;
|
} proxy_ctx_t;
|
||||||
|
Reference in New Issue
Block a user