]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: add content-type header information in http/3 responses, add relayed respons...
authorCharles-Henri Bruyand <charles-henri.bruyand@open-xchange.com>
Fri, 12 Jan 2024 15:08:00 +0000 (16:08 +0100)
committerCharles-Henri Bruyand <charles-henri.bruyand@open-xchange.com>
Fri, 12 Jan 2024 15:12:03 +0000 (16:12 +0100)
pdns/dnsdistdist/doh3.cc
pdns/dnsdistdist/doq.cc

index 4861e058ddf9efc7aade6d409d94ab317daff571..279b19b8402b7e91170169a3a07706a20d6e63c2 100644 (file)
@@ -159,7 +159,7 @@ public:
 
     if (!unit->ids.selfGenerated) {
       double udiff = unit->ids.queryRealTime.udiff();
-      vinfolog("Got answer from %s, relayed to %s (http/3), took %f us", unit->downstream->d_config.remote.toStringWithPort(), unit->ids.origRemote.toStringWithPort(), udiff);
+      vinfolog("Got answer from %s, relayed to %s (DoH3, %d bytes), took %f us", unit->downstream->d_config.remote.toStringWithPort(), unit->ids.origRemote.toStringWithPort(), unit->response.size(), udiff);
 
       auto backendProtocol = unit->downstream->getProtocol();
       if (backendProtocol == dnsdist::Protocol::DoUDP && unit->tcp) {
@@ -290,7 +290,7 @@ static void h3_send_response(H3Connection& conn, const uint64_t streamID, uint16
 {
   std::string status = std::to_string(statusCode);
   std::string lenStr = std::to_string(len);
-  std::array<quiche_h3_header, 2> headers{
+  std::array<quiche_h3_header, 3> headers{
     (quiche_h3_header){
       // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast): Quiche API
       .name = reinterpret_cast<const uint8_t*>(":status"),
@@ -307,9 +307,20 @@ static void h3_send_response(H3Connection& conn, const uint64_t streamID, uint16
       .value = reinterpret_cast<const uint8_t*>(lenStr.data()),
       .value_len = lenStr.size(),
     },
+    (quiche_h3_header){
+      // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast): Quiche API
+      .name = reinterpret_cast<const uint8_t*>("content-type"),
+      .name_len = sizeof("content-type") - 1,
+      // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast): Quiche API
+      .value = reinterpret_cast<const uint8_t*>("application/dns-message"),
+      .value_len = sizeof("application/dns-message") - 1,
+    },
   };
   auto returnValue = quiche_h3_send_response(conn.d_http3.get(), conn.d_conn.get(),
-                                             streamID, headers.data(), headers.size(), len == 0);
+                                             streamID, headers.data(),
+                                             // do not include content-type header info if there is no content
+                                             (len > 0 ? headers.size() : headers.size() - 1),
+                                             len == 0);
   if (returnValue != 0) {
     /* in theory it could be QUICHE_H3_ERR_STREAM_BLOCKED if the stream is not writable / congested, but we are not going to handle this case */
     quiche_conn_stream_shutdown(conn.d_conn.get(), streamID, QUICHE_SHUTDOWN_WRITE, static_cast<uint64_t>(dnsdist::doq::DOQ_Error_Codes::DOQ_INTERNAL_ERROR));
index 30572192ac83d45ac422e2edf92ad9c95d25f495..117437002c02bfa40a78127de7ddd31ec5dcb3fa 100644 (file)
@@ -156,7 +156,7 @@ public:
 
     if (!unit->ids.selfGenerated) {
       double udiff = unit->ids.queryRealTime.udiff();
-      vinfolog("Got answer from %s, relayed to %s (quic), took %f us", unit->downstream->d_config.remote.toStringWithPort(), unit->ids.origRemote.toStringWithPort(), udiff);
+      vinfolog("Got answer from %s, relayed to %s (quic, %d bytes), took %f us", unit->downstream->d_config.remote.toStringWithPort(), unit->ids.origRemote.toStringWithPort(), unit->response.size(), udiff);
 
       auto backendProtocol = unit->downstream->getProtocol();
       if (backendProtocol == dnsdist::Protocol::DoUDP && unit->tcp) {