Skip to content

Commit 6a49658

Browse files
committed
Include a Date: response header for rejected HTTP1 requests
This allows OpenBSD ntpd time constraint retrieval to work properly with nghttp2 incoming DoH. Note that requests having no alpn data do not appear in any stats. Should that be changed? Signed-off-by: Otto Moerbeek <otto.moerbeek@open-xchange.com>
1 parent dc033af commit 6a49658

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

pdns/dnsdistdist/dnsdist-nghttp2-in.cc

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,8 +282,20 @@ bool IncomingHTTP2Connection::checkALPN()
282282
++d_ci.cs->dohFrontend->d_http1Stats.d_nbQueries;
283283
}
284284

285-
const std::string data("HTTP/1.1 400 Bad Request\r\nConnection: Close\r\n\r\n<html><body>This server implements RFC 8484 - DNS Queries over HTTP, and requires HTTP/2 in accordance with section 5.2 of the RFC.</body></html>\r\n");
286-
d_out.insert(d_out.end(), data.begin(), data.end());
285+
static const std::string data0("HTTP/1.1 400 Bad Request\r\nConnection: Close\r\n");
286+
287+
std::array<char, 40> data1{};
288+
static const std::string dateformat("Date: %a, %d %h %Y %T GMT\r\n");
289+
struct tm tmval{};
290+
time_t timestamp = time(nullptr);
291+
size_t len = strftime(data1.data(), data1.size(), dateformat.data(), gmtime_r(&timestamp, &tmval));
292+
assert(len != 0);
293+
294+
static const std::string data2("\r\n<html><body>This server implements RFC 8484 - DNS Queries over HTTP, and requires HTTP/2 in accordance with section 5.2 of the RFC.</body></html>\r\n");
295+
296+
d_out.insert(d_out.end(), data0.begin(), data0.end());
297+
d_out.insert(d_out.end(), data1.begin(), data1.end());
298+
d_out.insert(d_out.end(), data2.begin(), data2.end());
287299
writeToSocket(false);
288300

289301
vinfolog("DoH connection from %s expected ALPN value 'h2', got '%s'", d_ci.remote.toStringWithPort(), std::string(protocols.begin(), protocols.end()));

0 commit comments

Comments
 (0)