From 259264905b80e0b413ded791addf8b75ed657e62 Mon Sep 17 00:00:00 2001 From: xywang Date: Wed, 10 Nov 2021 14:09:07 +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 | 8 +++++++- 3 files changed, 9 insertions(+), 2 deletions(-) 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..824ce74670 100644 --- a/src/plugins/http/src/httpResp.c +++ b/src/plugins/http/src/httpResp.c @@ -24,7 +24,7 @@ const char *httpKeepAliveStr[] = {"", "Connection: Keep-Alive\r\n", "Connection: Close\r\n"}; -const char *httpVersionStr[] = {"HTTP/1.0", "HTTP/1.1", "HTTP/1.2"}; +const char *httpVersionStr[] = {"HTTP/1.0", "HTTP/1.1", "HTTP/2.0"}; /* There is no version 1.2 */ const char *httpRespTemplate[] = { // HTTP_RESPONSE_JSON_OK @@ -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