From c1e3d0f5934daeffb53da9f046fe4e8a2f8d8d9c Mon Sep 17 00:00:00 2001 From: xywang Date: Wed, 10 Nov 2021 14:26:56 +0800 Subject: [PATCH] [TS-602]: added HTTP header "Connection: close" if 4xx/5xx were returned --- src/plugins/http/inc/httpInt.h | 2 +- src/plugins/http/src/httpContext.c | 1 + src/plugins/http/src/httpResp.c | 6 ++++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/plugins/http/inc/httpInt.h b/src/plugins/http/inc/httpInt.h index bf8efd2831..af0f4c5795 100644 --- a/src/plugins/http/inc/httpInt.h +++ b/src/plugins/http/inc/httpInt.h @@ -147,7 +147,7 @@ typedef struct HttpContext { int32_t state; uint8_t reqType; uint8_t parsed; - uint8_t error; + bool error; char ipstr[22]; char user[TSDB_USER_LEN]; // parsed from auth token or login message char pass[HTTP_PASSWORD_LEN]; diff --git a/src/plugins/http/src/httpContext.c b/src/plugins/http/src/httpContext.c index f26a4b4c8b..4922d98ee4 100644 --- a/src/plugins/http/src/httpContext.c +++ b/src/plugins/http/src/httpContext.c @@ -120,6 +120,7 @@ HttpContext *httpCreateContext(SOCKET fd) { pContext->lastAccessTime = taosGetTimestampSec(); pContext->state = HTTP_CONTEXT_STATE_READY; pContext->parser = httpCreateParser(pContext); + pContext->error = false; TSDB_CACHE_PTR_TYPE handleVal = (TSDB_CACHE_PTR_TYPE)pContext; HttpContext **ppContext = taosCachePut(tsHttpServer.contextCache, &handleVal, sizeof(TSDB_CACHE_PTR_TYPE), &pContext, diff --git a/src/plugins/http/src/httpResp.c b/src/plugins/http/src/httpResp.c index 1d05b455cb..4065f881d1 100644 --- a/src/plugins/http/src/httpResp.c +++ b/src/plugins/http/src/httpResp.c @@ -52,8 +52,14 @@ static void httpSendErrorRespImp(HttpContext *pContext, int32_t httpCode, char * int8_t httpVersion = 0; int8_t keepAlive = 0; + if (pContext->parser != NULL) { httpVersion = pContext->parser->httpVersion; + } + + if (pContext->error == true) { + keepAlive = HTTP_KEEPALIVE_DISABLE; + } else if (pContext->parser != NULL) { keepAlive = pContext->parser->keepAlive; } -- GitLab