Honor Connection: closed received from reverse proxy peers
This commit is contained in:
@ -139,6 +139,10 @@ proxy_ctx_t *proxy_get_by_conf(host_config_t *conf) {
|
|||||||
|
|
||||||
void proxy_unlock_ctx(proxy_ctx_t *ctx) {
|
void proxy_unlock_ctx(proxy_ctx_t *ctx) {
|
||||||
int n = (int) ((ctx - proxies) / MAX_PROXY_CNX_PER_HOST);
|
int n = (int) ((ctx - proxies) / MAX_PROXY_CNX_PER_HOST);
|
||||||
|
if (ctx->close) {
|
||||||
|
proxy_close(ctx);
|
||||||
|
ctx->close = 0;
|
||||||
|
}
|
||||||
debug("Released proxy connection slot %i/%i", (ctx - proxies) % MAX_PROXY_CNX_PER_HOST, MAX_PROXY_CNX_PER_HOST);
|
debug("Released proxy connection slot %i/%i", (ctx - proxies) % MAX_PROXY_CNX_PER_HOST, MAX_PROXY_CNX_PER_HOST);
|
||||||
ctx->in_use = 0;
|
ctx->in_use = 0;
|
||||||
ctx->client = NULL;
|
ctx->client = NULL;
|
||||||
@ -400,8 +404,9 @@ int proxy_init(proxy_ctx_t **proxy_ptr, http_req *req, http_res *res, http_statu
|
|||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
// honor server timeout with one second buffer
|
// honor server timeout with one second buffer
|
||||||
if (!proxy->initialized || sock_has_pending(&proxy->proxy, SOCK_DONTWAIT) != 0 || srv_error ||
|
if (!proxy->initialized || srv_error ||
|
||||||
(proxy->http_timeout != 0 && (clock_micros() - proxy->proxy.ts_last_send) >= proxy->http_timeout - 1000000))
|
(proxy->http_timeout > 0 && (clock_micros() - proxy->proxy.ts_last_send) >= proxy->http_timeout) ||
|
||||||
|
sock_has_pending(&proxy->proxy, SOCK_DONTWAIT))
|
||||||
{
|
{
|
||||||
if (proxy->initialized)
|
if (proxy->initialized)
|
||||||
proxy_close(proxy);
|
proxy_close(proxy);
|
||||||
@ -549,6 +554,9 @@ int proxy_init(proxy_ctx_t **proxy_ptr, http_req *req, http_res *res, http_statu
|
|||||||
long keep_alive_timeout = http_get_keep_alive_timeout(&res->hdr);
|
long keep_alive_timeout = http_get_keep_alive_timeout(&res->hdr);
|
||||||
proxy->http_timeout = (keep_alive_timeout > 0) ? keep_alive_timeout * 1000000 : 0;
|
proxy->http_timeout = (keep_alive_timeout > 0) ? keep_alive_timeout * 1000000 : 0;
|
||||||
|
|
||||||
|
connection = http_get_header_field(&res->hdr, "Connection");
|
||||||
|
proxy->close = !strcontains(connection, "keep-alive") && !strcontains(connection, "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);
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
volatile unsigned char initialized:1, in_use:1;
|
volatile unsigned char initialized:1, in_use:1, close:1;
|
||||||
sock proxy;
|
sock proxy;
|
||||||
long cnx_s, cnx_e;
|
long cnx_s, cnx_e;
|
||||||
long http_timeout;
|
long http_timeout;
|
||||||
|
Reference in New Issue
Block a user