From 8e88c835f36dac7f3d09f335bb2918d594976456 Mon Sep 17 00:00:00 2001 From: ilovenoah Date: Sat, 9 Mar 2024 15:54:57 +0900 Subject: [PATCH] add duplicate header in cgi response --- src/response/Response.cpp | 10 ++++++++-- .../request_file/duplicate_cgi_response_header.txt | 7 +++++++ .../response_file/duplicate_cgi_response_header.txt | 6 ++++++ .../www/cgi-bin/duplicate_cgi_response_header.py | 9 +++++++++ 4 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 tests/simple_server_function_test/request_file/duplicate_cgi_response_header.txt create mode 100644 tests/simple_server_function_test/response_file/duplicate_cgi_response_header.txt create mode 100755 tests/simple_server_function_test/www/cgi-bin/duplicate_cgi_response_header.py diff --git a/src/response/Response.cpp b/src/response/Response.cpp index 079c3f2..e99db4e 100644 --- a/src/response/Response.cpp +++ b/src/response/Response.cpp @@ -465,8 +465,14 @@ void Response::_setCGIResponseHeader(const bool shouldKeepAlive) { if (utils::compCaseInsensitive(key, "Set-Cookie") == 0) { this->_setCookies.push_back(value); } else { - this->_headers.insert( - std::pair(key, value)); + std::map::iterator iter = + this->_headers.find(key); + if (iter != this->_headers.end()) { + iter->second.append(", " + value); + } else { + this->_headers.insert( + std::pair(key, value)); + } } } std::streampos endPos = ss.tellg(); diff --git a/tests/simple_server_function_test/request_file/duplicate_cgi_response_header.txt b/tests/simple_server_function_test/request_file/duplicate_cgi_response_header.txt new file mode 100644 index 0000000..496b5de --- /dev/null +++ b/tests/simple_server_function_test/request_file/duplicate_cgi_response_header.txt @@ -0,0 +1,7 @@ +host, localhost +port, 8080 + + +GET /cgi-bin/duplicate_cgi_response_header.py HTTP/1.1 +Host: test +Connection: close \ No newline at end of file diff --git a/tests/simple_server_function_test/response_file/duplicate_cgi_response_header.txt b/tests/simple_server_function_test/response_file/duplicate_cgi_response_header.txt new file mode 100644 index 0000000..38bf57e --- /dev/null +++ b/tests/simple_server_function_test/response_file/duplicate_cgi_response_header.txt @@ -0,0 +1,6 @@ +HTTP/1.1 200 Ok +Connection: close +Content-Type: text/html +Status: 200 OK +X_test: test1, test2, test3 + diff --git a/tests/simple_server_function_test/www/cgi-bin/duplicate_cgi_response_header.py b/tests/simple_server_function_test/www/cgi-bin/duplicate_cgi_response_header.py new file mode 100755 index 0000000..bd6faa6 --- /dev/null +++ b/tests/simple_server_function_test/www/cgi-bin/duplicate_cgi_response_header.py @@ -0,0 +1,9 @@ +import os + +# ステータスとコンテントタイプのヘッダーを出力 +print("Status: 200 OK") +print("Content-Type: text/html") +print("X_test: test1") +print("X_test: test2") +print("X_test: test3") +print() # ヘッダーの終わりを示す空行 \ No newline at end of file