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

llnl / dftracer-utils / 30069185152

24 Jul 2026 05:20AM UTC coverage: 50.687% (-2.0%) from 52.66%
30069185152

Pull #99

github

web-flow
Merge 47af36077 into 06bc84ec9
Pull Request #99: Support CM time_metric (NS/MS/SEC/US) across reader and viz

18062 of 48203 branches covered (37.47%)

Branch coverage included in aggregate %.

1510 of 2205 new or added lines in 59 files covered. (68.48%)

742 existing lines in 114 files now uncovered.

23711 of 34210 relevant lines covered (69.31%)

39853.91 hits per line

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

67.66
/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) {
64✔
11
    if (a.size() != b.size()) return false;
64✔
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(
64✔
19
    const std::vector<std::pair<std::string, std::string>> &headers) {
20
    return std::any_of(headers.begin(), headers.end(), [](const auto &h) {
64✔
21
        return icase_equal(h.first, "Content-Length");
64!
22
    });
64✔
23
}
24

25
}  // namespace
26

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

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

37
    // Loopback-bound (and optionally token-gated), so allow any origin: this
38
    // lets the VS Code webview, hosted at a vscode-webview:// origin, read the
39
    // API cross-origin.
40
    out += "Access-Control-Allow-Origin: *\r\n";
70!
41

42
    for (const auto &[name, value] : headers) {
147✔
43
        out += name;
77!
44
        out += ": ";
77!
45
        out += value;
77!
46
        out += "\r\n";
77!
47
    }
48

49
    if (!body.empty() && !has_content_length(headers)) {
70!
50
        out += "Content-Length: ";
63!
51
        out += std::to_string(body.size());
63!
52
        out += "\r\n";
63!
53
    }
54

55
    out += "\r\n";
70!
56
    return out;
70✔
UNCOV
57
}
×
58

59
std::string HttpResponse::serialize() const {
63✔
60
    auto out = serialize_headers();
63✔
61
    out += body;
63!
62
    return out;
63✔
UNCOV
63
}
×
64

65
HttpResponse HttpResponse::ok() {
2✔
66
    return HttpResponse{
67
        .status_code = 200, .status_text = "OK", .headers = {}, .body = {}};
2!
68
}
69

70
HttpResponse HttpResponse::ok(const std::string &body,
60✔
71
                              const std::string &content_type) {
72
    return HttpResponse{.status_code = 200,
73
                        .status_text = "OK",
74
                        .headers = {{"Content-Type", content_type}},
75
                        .body = body};
120!
76
}
77

78
HttpResponse HttpResponse::not_found() {
3✔
79
    return HttpResponse{.status_code = 404,
80
                        .status_text = "Not Found",
81
                        .headers = {{"Content-Type", "text/plain"}},
82
                        .body = "Not Found"};
6!
83
}
84

85
HttpResponse HttpResponse::bad_request(const std::string &msg) {
4✔
86
    return HttpResponse{.status_code = 400,
87
                        .status_text = "Bad Request",
88
                        .headers = {{"Content-Type", "text/plain"}},
89
                        .body = msg};
8!
90
}
91

92
HttpResponse HttpResponse::internal_error(const std::string &msg) {
1✔
93
    return HttpResponse{.status_code = 500,
94
                        .status_text = "Internal Server Error",
95
                        .headers = {{"Content-Type", "text/plain"}},
96
                        .body = msg};
2!
97
}
98

99
HttpResponse HttpResponse::streaming(std::unique_ptr<StreamGenerator> gen,
3✔
100
                                     const std::string &content_type) {
101
    HttpResponse resp;
3✔
102
    resp.status_code = 200;
3✔
103
    resp.status_text = "OK";
3!
104
    resp.headers = {{"Content-Type", content_type},
12!
105
                    {"Transfer-Encoding", "chunked"}};
9!
106
    resp.stream = std::move(gen);
3✔
107
    return resp;
3✔
UNCOV
108
}
×
109

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

© 2026 Coveralls, Inc