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

llnl / dftracer-utils / 27171677342

08 Jun 2026 10:43PM UTC coverage: 51.99% (+0.05%) from 51.937%
27171677342

Pull #77

github

web-flow
Merge 3a1432eec into 8045f0be3
Pull Request #77: chore: bump version to 0.0.10

36972 of 92663 branches covered (39.9%)

Branch coverage included in aggregate %.

33405 of 42703 relevant lines covered (78.23%)

20411.31 hits per line

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

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

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

25
}  // namespace
26

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

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

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

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

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

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

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

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

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

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

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

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