| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // | ||
| 2 | // Copyright (c) 2025 Amlal El Mahrouss (amlal at nekernel dot org) | ||
| 3 | // | ||
| 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying | ||
| 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | ||
| 6 | // | ||
| 7 | // Official repository: https://github.com/cppalliance/http_proto | ||
| 8 | // | ||
| 9 | |||
| 10 | #include <boost/http_proto/server/helmet.hpp> | ||
| 11 | |||
| 12 | namespace boost { | ||
| 13 | namespace http_proto { | ||
| 14 | |||
| 15 | namespace detail { | ||
| 16 | ✗ | auto setHeaderValues(const std::vector<std::string>& fields_value) -> std::string { | |
| 17 | ✗ | if (fields_value.empty()) | |
| 18 | ✗ | detail::throw_invalid_argument(); | |
| 19 | |||
| 20 | ✗ | std::string res_value; | |
| 21 | ✗ | bool first = false; | |
| 22 | |||
| 23 | ✗ | for (const auto& value: fields_value) | |
| 24 | { | ||
| 25 | ✗ | if (first) res_value += "; "; | |
| 26 | ✗ | res_value += value; | |
| 27 | ✗ | first = true; | |
| 28 | } | ||
| 29 | |||
| 30 | ✗ | return res_value; | |
| 31 | ✗ | } | |
| 32 | } | ||
| 33 | |||
| 34 | ✗ | helmet:: | |
| 35 | helmet( | ||
| 36 | ✗ | helmet_options options) noexcept | |
| 37 | ✗ | : options_(std::move(options)) | |
| 38 | { | ||
| 39 | ✗ | for (auto& hdr : options_.requestHeaders.headers) | |
| 40 | { | ||
| 41 | ✗ | if (hdr.second.empty()) | |
| 42 | ✗ | detail::throw_length_error(); | |
| 43 | |||
| 44 | ✗ | options_.requestHeaders.cachedHeaders.push_back(std::make_pair(hdr.first, detail::setHeaderValues(hdr.second))); | |
| 45 | } | ||
| 46 | ✗ | } | |
| 47 | |||
| 48 | route_result | ||
| 49 | ✗ | helmet:: | |
| 50 | operator()( | ||
| 51 | route_params& p) const | ||
| 52 | { | ||
| 53 | ✗ | for (const auto& hdr : options_.requestHeaders.cachedHeaders) | |
| 54 | { | ||
| 55 | ✗ | p.res.set(hdr.first, hdr.second); | |
| 56 | } | ||
| 57 | |||
| 58 | ✗ | return route::next; | |
| 59 | } | ||
| 60 | |||
| 61 | } | ||
| 62 | } | ||
| 63 |