From 71eb0ef4bf1c833458a5b6954ae03801c0786d4b Mon Sep 17 00:00:00 2001 From: Tomasz Sowa Date: Fri, 17 Mar 2017 10:12:41 +0000 Subject: [PATCH] fixed: when connection header is set to keep-alive we should respond 'Connection: keep-alive' too git-svn-id: svn://ttmath.org/publicrep/libscorpiohttpserver/trunk@1059 e52654a7-88a9-db11-a3e9-0013d4bc506e --- src/server.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/server.cpp b/src/server.cpp index f2872af..4c4c9e1 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -372,8 +372,15 @@ void Server::CheckHeaders(Client & client, size_t input_buffer_index) if( client.http_version == http_version_1_0 ) { - std::cout << "answer generated, closing connection for http 1.0" << std::endl; - client.close_connection = true; + if( !CompareNoCase(client.in.Text(L"connection"), L"keep-alive") ) + { + std::cout << "answer generated, closing connection for http 1.0" << std::endl; + client.close_connection = true; + } + else + { + std::cout << "keep-alive is set, not closing connection for http 1.0" << std::endl; + } } } @@ -477,6 +484,11 @@ void Server::CreateAnswer(Client & client) a += L"Content-Type: text/html; charset=UTF-8\r\n"; + if( CompareNoCase(client.in.Text(L"connection"), L"keep-alive") ) + { + a += L"Connection: keep-alive\r\n"; + } + wchar_t buf[32]; swprintf(buf, sizeof(buf)/sizeof(wchar_t), L"%d", c_ascii.size());