Skip to content

Commit 8f74a6a

Browse files
Sightemgittiver
authored andcommitted
Omit Server header when server_name is empty
According to RFC 9110 Section 10.2.4, the Server header field in responses is optional (MAY be sent). This change modifies the connection logic to prevent automatically adding the 'Server' header if the application-wide server_name is configured to be an empty string via `app.server_name("")`. Addresses issue #1020
1 parent 1c5a034 commit 8f74a6a

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

include/crow/app.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ namespace crow
329329
return *this;
330330
}
331331

332-
/// \brief Set the server name
332+
/// \brief Set the server name included in the 'Server' HTTP response header. If set to an empty string, the header will be omitted by default.
333333
self_t& server_name(std::string server_name)
334334
{
335335
server_name_ = server_name;

include/crow/http_connection.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ namespace crow
365365
buffers_.emplace_back(content_length_.data(), content_length_.size());
366366
buffers_.emplace_back(crlf.data(), crlf.size());
367367
}
368-
if (!res.headers.count("server"))
368+
if (!res.headers.count("server") && !server_name_.empty())
369369
{
370370
static std::string server_tag = "Server: ";
371371
buffers_.emplace_back(server_tag.data(), server_tag.size());

0 commit comments

Comments
 (0)