Handle connection closures from proxy peers in async

This commit is contained in:
2023-07-07 21:54:58 +02:00
parent ef3e8475fb
commit ddb6623651
10 changed files with 60 additions and 11 deletions

View File

@ -71,6 +71,8 @@ void fastcgi_frame_handler_func(fastcgi_ctx_t *ctx);
void proxy_handler_func(client_ctx_t *ctx);
void proxy_peer_handler_func(proxy_ctx_t *ctx);
void ws_frame_handler_func(ws_ctx_t *ctx);
void chunk_handler_func(chunk_ctx_t *ctx);

View File

@ -27,16 +27,21 @@ void proxy_handler_func(client_ctx_t *ctx) {
respond(ctx);
if (ret == 1) {
proxy_unlock_ctx(ctx->proxy);
// error status code
if (proxy_unlock_ctx(ctx->proxy) == 1)
proxy_peer_handle(ctx->proxy);
} else if (ctx->use_proxy == 0) {
// proxy not used
proxy_close(ctx->proxy);
proxy_unlock_ctx(ctx->proxy);
} else if (ctx->use_proxy == 1) {
// proxy is used
if (proxy_handler_2(ctx) == 1) {
// chunked
return;
}
proxy_unlock_ctx(ctx->proxy);
if (proxy_unlock_ctx(ctx->proxy) == 1)
proxy_peer_handle(ctx->proxy);
} else if (ctx->use_proxy == 2) {
// WebSocket
ws_handle_connection(ctx);
@ -112,7 +117,8 @@ static int proxy_handler_1(client_ctx_t *ctx) {
}
static void proxy_chunk_next_cb(chunk_ctx_t *ctx) {
proxy_unlock_ctx(ctx->client->proxy);
if (proxy_unlock_ctx(ctx->client->proxy) == 1)
proxy_peer_handle(ctx->client->proxy);
ctx->client->proxy = NULL;
request_complete(ctx->client);

View File

@ -0,0 +1,17 @@
/**
* sesimos - secure, simple, modern web server
* @brief Proxy peer handler
* @file src/worker/proxy_peer_handler.c
* @author Lorenz Stechauner
* @date 2023-07-07
*/
#include "func.h"
#include "../logger.h"
#include "../lib/utils.h"
void proxy_peer_handler_func(proxy_ctx_t *ctx) {
if (!ctx->initialized || ctx->in_use) return;
logger_set_prefix("[%s%*s%s]", BLD_STR, ADDRSTRLEN, ctx->host, CLR_STR);
proxy_close(ctx);
}