• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

llnl / dftracer-utils / 26195612357

20 May 2026 11:19PM UTC coverage: 49.859% (-2.3%) from 52.2%
26195612357

push

github

hariharan-devarajan
feat(aggregator): improve system metrics scanning and persistence error handling

16041 of 43831 branches covered (36.6%)

Branch coverage included in aggregate %.

6 of 17 new or added lines in 2 files covered. (35.29%)

1072 existing lines in 104 files now uncovered.

21423 of 31309 relevant lines covered (68.42%)

13054.31 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

67.68
/src/dftracer/utils/server/http_response.cpp
1
#include <dftracer/utils/server/http_response.h>
2

3
#include <algorithm>
4
#include <cctype>
5

6
namespace dftracer::utils::server {
7

8
namespace {
9

10
bool icase_equal(std::string_view a, std::string_view b) {
18✔
11
    if (a.size() != b.size()) return false;
18✔
12
    return std::equal(a.begin(), a.end(), b.begin(), [](char ca, char cb) {
1✔
13
        return std::tolower(static_cast<unsigned char>(ca)) ==
14✔
14
               std::tolower(static_cast<unsigned char>(cb));
14✔
15
    });
1✔
16
}
17

18
bool has_content_length(
18✔
19
    const std::vector<std::pair<std::string, std::string>> &headers) {
20
    return std::any_of(headers.begin(), headers.end(), [](const auto &h) {
18✔
21
        return icase_equal(h.first, "Content-Length");
18!
22
    });
18✔
23
}
24

25
}  // namespace
26

27
std::string HttpResponse::serialize_headers() const {
22✔
28
    std::string out;
22✔
29
    out.reserve(256);
22!
30

31
    out += "HTTP/1.1 ";
22!
32
    out += std::to_string(status_code);
22!
33
    out += ' ';
22!
34
    out += status_text;
22!
35
    out += "\r\n";
22!
36

37
    for (const auto &[name, value] : headers) {
48✔
38
        out += name;
26!
39
        out += ": ";
26!
40
        out += value;
26!
41
        out += "\r\n";
26!
42
    }
43

44
    if (!body.empty() && !has_content_length(headers)) {
22!
45
        out += "Content-Length: ";
17!
46
        out += std::to_string(body.size());
17!
47
        out += "\r\n";
17!
48
    }
49

50
    out += "\r\n";
22!
51
    return out;
22✔
UNCOV
52
}
×
53

54
std::string HttpResponse::serialize() const {
16✔
55
    auto out = serialize_headers();
16✔
56
    out += body;
16!
57
    return out;
16✔
UNCOV
58
}
×
59

60
HttpResponse HttpResponse::ok() {
2✔
61
    return HttpResponse{
62
        .status_code = 200, .status_text = "OK", .headers = {}, .body = {}};
2!
63
}
64

65
HttpResponse HttpResponse::ok(const std::string &body,
15✔
66
                              const std::string &content_type) {
67
    return HttpResponse{.status_code = 200,
68
                        .status_text = "OK",
69
                        .headers = {{"Content-Type", content_type}},
70
                        .body = body};
30!
71
}
72

73
HttpResponse HttpResponse::not_found() {
3✔
74
    return HttpResponse{.status_code = 404,
75
                        .status_text = "Not Found",
76
                        .headers = {{"Content-Type", "text/plain"}},
77
                        .body = "Not Found"};
6!
78
}
79

80
HttpResponse HttpResponse::bad_request(const std::string &msg) {
3✔
81
    return HttpResponse{.status_code = 400,
82
                        .status_text = "Bad Request",
83
                        .headers = {{"Content-Type", "text/plain"}},
84
                        .body = msg};
6!
85
}
86

87
HttpResponse HttpResponse::internal_error(const std::string &msg) {
1✔
88
    return HttpResponse{.status_code = 500,
89
                        .status_text = "Internal Server Error",
90
                        .headers = {{"Content-Type", "text/plain"}},
91
                        .body = msg};
2!
92
}
93

94
HttpResponse HttpResponse::streaming(std::unique_ptr<StreamGenerator> gen,
2✔
95
                                     const std::string &content_type) {
96
    HttpResponse resp;
2✔
97
    resp.status_code = 200;
2✔
98
    resp.status_text = "OK";
2!
99
    resp.headers = {{"Content-Type", content_type},
8!
100
                    {"Transfer-Encoding", "chunked"}};
6!
101
    resp.stream = std::move(gen);
2✔
102
    return resp;
2✔
UNCOV
103
}
×
104

105
}  // namespace dftracer::utils::server
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc