From 44e3b1332fdf3d12a0c067b88b7519d50a6b0ca9 Mon Sep 17 00:00:00 2001 From: Lorenz Stechauner Date: Sat, 1 Jul 2023 21:50:33 +0200 Subject: [PATCH] Add first steps to honor timeout from server as proxy --- src/lib/proxy.c | 7 ++++++- src/lib/proxy.h | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/lib/proxy.c b/src/lib/proxy.c index 481e06b..67db2b8 100644 --- a/src/lib/proxy.c +++ b/src/lib/proxy.c @@ -352,6 +352,7 @@ static int proxy_connect(proxy_ctx_t *proxy, host_config_t *conf, http_res *res, proxy->initialized = 1; proxy->cnx_s = clock_micros(); proxy->host = conf->name; + proxy->timeout = 0; 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) { 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) 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); + // TODO read timeout from Keep-Alive + ret = proxy_response_header(req, res, conf); if (ret != 0) { res->status = http_get_status(500); diff --git a/src/lib/proxy.h b/src/lib/proxy.h index fbed1dc..8b5844d 100644 --- a/src/lib/proxy.h +++ b/src/lib/proxy.h @@ -22,6 +22,7 @@ typedef struct { unsigned char initialized:1, in_use:1; sock proxy; long cnx_s, cnx_e; + long timeout; char *host; void *client; } proxy_ctx_t;