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

PowerDNS / pdns / 13012068652

28 Jan 2025 01:59PM UTC coverage: 64.71% (+0.01%) from 64.699%
13012068652

Pull #14724

github

web-flow
Merge b15562560 into db18c3a17
Pull Request #14724: dnsdist: Add meson support

38328 of 90334 branches covered (42.43%)

Branch coverage included in aggregate %.

361 of 513 new or added lines in 35 files covered. (70.37%)

42 existing lines in 13 files now uncovered.

128150 of 166934 relevant lines covered (76.77%)

4540890.91 hits per line

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

73.21
/pdns/dnsdistdist/dnsdist-lua-web.cc
1
/*
2
 * This file is part of PowerDNS or dnsdist.
3
 * Copyright -- PowerDNS.COM B.V. and its contributors
4
 *
5
 * This program is free software; you can redistribute it and/or modify
6
 * it under the terms of version 2 of the GNU General Public License as
7
 * published by the Free Software Foundation.
8
 *
9
 * In addition, for the avoidance of any doubt, permission is granted to
10
 * link this program with OpenSSL and to (re)distribute the binaries
11
 * produced as the result of such linking.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program; if not, write to the Free Software
20
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21
 */
22
#include <yahttp/yahttp.hpp>
23

24
#include "dnsdist.hh"
25
#include "dnsdist-lua.hh"
26
#include "dnsdist-web.hh"
27

28
namespace dnsdist::webserver
29
{
30
void registerWebHandler(const std::string& endpoint, std::function<void(const YaHTTP::Request&, YaHTTP::Response&)> handler, bool isLua);
31
}
32

33
void setupLuaWeb([[maybe_unused]] LuaContext& luaCtx)
34
{
673✔
35
#ifndef DISABLE_LUA_WEB_HANDLERS
673✔
36
  luaCtx.writeFunction("registerWebHandler", [](const std::string& path, std::function<void(const YaHTTP::Request*, YaHTTP::Response*)> handler) {
673✔
37
    /* LuaWrapper does a copy for objects passed by reference, so we pass a pointer */
38
    dnsdist::webserver::registerWebHandler(path, [handler](const YaHTTP::Request& req, YaHTTP::Response& resp) { handler(&req, &resp); }, true);
2✔
39
  });
2✔
40

41
  luaCtx.registerMember<std::string(YaHTTP::Request::*)>("path", [](const YaHTTP::Request& req) -> std::string { return req.url.path; }, [](YaHTTP::Request& req, const std::string& path) { (void)req; (void) path; });
673✔
42
  luaCtx.registerMember<int(YaHTTP::Request::*)>("version", [](const YaHTTP::Request& req) -> int { return req.version; }, [](YaHTTP::Request& req, int version) { (void)req; (void)version; });
673✔
43
  luaCtx.registerMember<std::string(YaHTTP::Request::*)>("method", [](const YaHTTP::Request& req) -> std::string { return req.method; }, [](YaHTTP::Request& req, const std::string& method) { (void)req; (void) method; });
673✔
44
  luaCtx.registerMember<std::string(YaHTTP::Request::*)>("body", [](const YaHTTP::Request& req) -> const std::string { return req.body; }, [](YaHTTP::Request& req, const std::string& body) { (void)req; (void)body; });
673✔
45
  luaCtx.registerMember<LuaAssociativeTable<std::string>(YaHTTP::Request::*)>("getvars", [](const YaHTTP::Request& req) {
673✔
46
    LuaAssociativeTable<std::string> values;
1✔
47
    for (const auto& entry : req.getvars) {
1✔
48
      values.insert({entry.first, entry.second});
1✔
49
    }
1✔
50
    return values;
1✔
51
  }, [](YaHTTP::Request& req, const LuaAssociativeTable<std::string>& values) { (void)req; (void)values; });
1✔
52
  luaCtx.registerMember<LuaAssociativeTable<std::string>(YaHTTP::Request::*)>("postvars", [](const YaHTTP::Request& req) {
673✔
53
    LuaAssociativeTable<std::string> values;
×
54
    for (const auto& entry : req.postvars) {
×
55
      values.insert({entry.first, entry.second});
×
56
    }
×
57
    return values;
×
NEW
58
  }, [](YaHTTP::Request& req, const LuaAssociativeTable<std::string>& values) { (void)req; (void)values; });
×
59
  luaCtx.registerMember<LuaAssociativeTable<std::string>(YaHTTP::Request::*)>("headers", [](const YaHTTP::Request& req) {
673✔
60
    LuaAssociativeTable<std::string> values;
1✔
61
    for (const auto& entry : req.headers) {
7✔
62
      values.insert({entry.first, entry.second});
7✔
63
    }
7✔
64
    return values;
1✔
65
  }, [](YaHTTP::Request& req, const LuaAssociativeTable<std::string>& values) { (void)req; (void)values; });
1✔
66

67
  /* Response */
68
  luaCtx.registerMember<std::string(YaHTTP::Response::*)>("body", [](const YaHTTP::Response& resp) -> const std::string { return resp.body; }, [](YaHTTP::Response& resp, const std::string& body) { resp.body = body; });
673✔
69
  luaCtx.registerMember<int(YaHTTP::Response::*)>("status", [](const YaHTTP::Response& resp) -> int { return resp.status; }, [](YaHTTP::Response& resp, int status) { resp.status = status; });
673✔
70
  luaCtx.registerMember<LuaAssociativeTable<std::string>(YaHTTP::Response::*)>("headers", [](const YaHTTP::Response& resp) {
673✔
71
    LuaAssociativeTable<std::string> values;
×
72
    for (const auto& entry : resp.headers) {
×
73
      values.insert({entry.first, entry.second});
×
74
    }
×
75
    return values;
×
76
  }, [](YaHTTP::Response& resp, const LuaAssociativeTable<std::string>& values) {
1✔
77
    resp.headers.clear();
1✔
78
    for (const auto& entry : values) {
1✔
79
      resp.headers.insert({entry.first, entry.second});
1✔
80
    }
1✔
81
  });
1✔
82
#endif /* DISABLE_LUA_WEB_HANDLERS */
673✔
83
}
673✔
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

© 2025 Coveralls, Inc