Skip to content

Commit

Permalink
Merge pull request #13607 from rgacogne/ddist18-13071
Browse files Browse the repository at this point in the history
dnsdist-1.8.x: Fix code producing json
  • Loading branch information
rgacogne committed Dec 14, 2023
2 parents 0dbfe48 + 05aecc5 commit 58617c4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
10 changes: 9 additions & 1 deletion ext/json11/json11.cpp
Expand Up @@ -93,10 +93,18 @@ static void dump(const string &value, string &out) {
out += "\\r";
} else if (ch == '\t') {
out += "\\t";
} else if (static_cast<uint8_t>(ch) <= 0x1f || static_cast<uint8_t>(ch) >= 0x7f) {
} else if (static_cast<uint8_t>(ch) <= 0x1f) {
char buf[8];
snprintf(buf, sizeof buf, "\\u%04x", ch);
out += buf;
} else if (static_cast<uint8_t>(ch) == 0xe2 && static_cast<uint8_t>(value[i+1]) == 0x80
&& static_cast<uint8_t>(value[i+2]) == 0xa8) {
out += "\\u2028";
i += 2;
} else if (static_cast<uint8_t>(ch) == 0xe2 && static_cast<uint8_t>(value[i+1]) == 0x80
&& static_cast<uint8_t>(value[i+2]) == 0xa9) {
out += "\\u2029";
i += 2;
} else {
out += ch;
}
Expand Down
2 changes: 1 addition & 1 deletion pdns/webserver.cc
Expand Up @@ -535,7 +535,7 @@ void WebServer::serveConnection(const std::shared_ptr<Socket>& client) const {
}

if (d_loglevel >= WebServer::LogLevel::Normal) {
SLOG(g_log<<Logger::Notice<<logprefix<<remote<<" \""<<req.method<<" "<<YaHTTP::Utility::encodeURL(req.url.path)<<" HTTP/"<<req.versionStr(req.version)<<"\" "<<resp.status<<" "<<reply.size()<<endl,
SLOG(g_log<<Logger::Notice<<logprefix<<remote<<" \""<<req.method<<" "<<req.url.path<<" HTTP/"<<req.versionStr(req.version)<<"\" "<<resp.status<<" "<<reply.size()<<endl,
d_slog->info(Logr::Info, "Request", "remote", Logging::Loggable(remote), "method", Logging::Loggable(req.method),
"urlpath", Logging::Loggable(req.url.path), "HTTPVersion", Logging::Loggable(req.versionStr(req.version)),
"status", Logging::Loggable(resp.status), "respsize", Logging::Loggable(reply.size())));
Expand Down
11 changes: 1 addition & 10 deletions regression-tests.api/test_Servers.py
Expand Up @@ -2,7 +2,6 @@
import operator
import requests
import unittest
import socket
from test_helper import ApiTestCase, is_auth, is_recursor, is_auth_lmdb


Expand Down Expand Up @@ -42,18 +41,13 @@ def test_read_config(self):
self.assertIn('daemon', data)

def test_read_statistics(self):
# Use low-level API as we want to create an invalid request to test log line encoding
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM);
sock.connect((self.server_address, self.server_port))
sock.send(b'GET /binary\x00\x01\xeb HTTP/1.0\r\n')
sock.close()
r = self.session.get(self.url("/api/v1/servers/localhost/statistics"))
self.assert_success_json(r)
data = r.json()
self.assertIn('uptime', [e['name'] for e in data])
print(data)
if is_auth():
qtype_stats, respsize_stats, queries_stats, rcode_stats, logmessages = None, None, None, None, None
qtype_stats, respsize_stats, queries_stats, rcode_stats = None, None, None, None
for elem in data:
if elem['type'] == 'MapStatisticItem' and elem['name'] == 'response-by-qtype':
qtype_stats = elem['value']
Expand All @@ -63,13 +57,10 @@ def test_read_statistics(self):
queries_stats = elem['value']
elif elem['type'] == 'MapStatisticItem' and elem['name'] == 'response-by-rcode':
rcode_stats = elem['value']
elif elem['type'] == 'RingStatisticItem' and elem['name'] == 'logmessages':
logmessages = elem['value']
self.assertIn('A', [e['name'] for e in qtype_stats])
self.assertIn('80', [e['name'] for e in respsize_stats])
self.assertIn('example.com/A', [e['name'] for e in queries_stats])
self.assertIn('No Error', [e['name'] for e in rcode_stats])
self.assertTrue(logmessages[0]['name'].startswith('[webserver]'))
else:
qtype_stats, respsize_stats, rcode_stats = None, None, None
for elem in data:
Expand Down

0 comments on commit 58617c4

Please sign in to comment.