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

llnl / dftracer-utils / 29787659139

20 Jul 2026 11:34PM UTC coverage: 51.578% (-1.1%) from 52.66%
29787659139

Pull #99

github

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

34832 of 86278 branches covered (40.37%)

Branch coverage included in aggregate %.

1034 of 1319 new or added lines in 30 files covered. (78.39%)

5193 existing lines in 197 files now uncovered.

35349 of 49791 relevant lines covered (70.99%)

9765.54 hits per line

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

69.51
/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) {
55✔
11
    if (a.size() != b.size()) return false;
55✔
12
    return std::equal(a.begin(), a.end(), b.begin(), [](char ca, char cb) {
15✔
13
        return std::tolower(static_cast<unsigned char>(ca)) ==
28✔
14
               std::tolower(static_cast<unsigned char>(cb));
14✔
15
    });
16
}
55✔
17

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

25
}  // namespace
26

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

31
    out += "HTTP/1.1 ";
61!
32
    out += std::to_string(status_code);
61!
33
    out += ' ';
61!
34
    out += status_text;
61!
35
    out += "\r\n";
61!
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";
61!
41

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

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

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

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

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

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

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

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

92
HttpResponse HttpResponse::internal_error(const std::string &msg) {
1✔
93
    return HttpResponse{.status_code = 500,
3!
94
                        .status_text = "Internal Server Error",
1✔
95
                        .headers = {{"Content-Type", "text/plain"}},
1!
96
                        .body = msg};
1!
UNCOV
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},
3!
105
                    {"Transfer-Encoding", "chunked"}};
3!
106
    resp.stream = std::move(gen);
3✔
107
    return resp;
3✔
108
}
3!
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