Skip to content

Commit 24e374b

Browse files
fix: helmet.cpp: documentation and move constructor fixes.
Signed-off-by: Amlal El Mahrouss <[email protected]>
1 parent ef40e62 commit 24e374b

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

include/boost/http_proto/server/helmet.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ using option_pair = std::pair<std::string, std::vector<std::string>>;
232232
opts.set(x_frame_origin(helmet_origin_type::deny));
233233
234234
helmet::csp_policy csp;
235-
csp.set("script-src", csp_type::self);
235+
csp.allow("script-src", csp_type::self);
236236
opts.set(content_security_policy(csp));
237237
238238
srv.wwwroot.use(helmet(opts));
@@ -268,9 +268,9 @@ class helmet
268268
@par Example
269269
@code
270270
helmet::csp_policy policy;
271-
policy.set("script-src", csp_type::self)
272-
.set("style-src", "https://example.com")
273-
.set("img-src", csp_type::none);
271+
policy.allow("script-src", csp_type::self)
272+
.allow("style-src", "https://example.com")
273+
.allow("img-src", csp_type::none);
274274
@endcode
275275
*/
276276
struct csp_policy
@@ -284,7 +284,7 @@ class helmet
284284
BOOST_HTTP_PROTO_DECL
285285
~csp_policy();
286286

287-
/** Append a CSP directive with a predefined type.
287+
/** Allows a CSP directive with a predefined type.
288288
289289
@param allow The directive name (e.g., "script-src").
290290
@param type The CSP source expression type.

src/server/helmet.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,8 @@ helmet& helmet::operator=(helmet&& other) noexcept
113113

114114
helmet::
115115
helmet(helmet&& other) noexcept
116+
: impl_(other.impl_)
116117
{
117-
delete impl_;
118-
impl_ = other.impl_;
119118
other.impl_ = nullptr;
120119
}
121120

@@ -156,7 +155,8 @@ helmet::csp_policy& helmet::csp_policy::allow(const core::string_view& allow,
156155
value += source.data();
157156

158157
auto it = std::find_if(list.begin(), list.end(), [&allow](const std::string& in) {
159-
return in.find(allow) != std::string::npos;
158+
std::string allow_with_space = std::string(allow) + " ";
159+
return in.find(allow_with_space) != std::string::npos;
160160
});
161161

162162
if (it == list.end())
@@ -224,7 +224,8 @@ helmet::csp_policy& helmet::csp_policy::allow(const core::string_view& allow, co
224224
}
225225

226226
auto it = std::find_if(list.begin(), list.end(), [&allow](const std::string& in) {
227-
return in.find(allow) != std::string::npos;
227+
std::string allow_with_space = std::string(allow) + " ";
228+
return in.find(allow_with_space) != std::string::npos;
228229
});
229230

230231
if (it == list.end())
@@ -250,7 +251,8 @@ helmet::csp_policy::~csp_policy() = default;
250251
helmet::csp_policy& helmet::csp_policy::remove(const core::string_view& allow)
251252
{
252253
if (auto it = std::find_if(list.cbegin(), list.cend(), [&allow](const std::string& in) {
253-
return in.find(allow) != std::string::npos;
254+
std::string allow_with_space = std::string(allow) + " ";
255+
return in.find(allow_with_space) != std::string::npos;
254256
}); it != list.cend())
255257
{
256258
list.erase(it);

0 commit comments

Comments
 (0)