clang-format: re-format for clang-18
clang-format-18 isn't compatible with the clang-format-17 output, so we
need to reformat the code with the latest version. The way clang-18
handles lambda formatting also changed, so we have made changes to the
organization default style format to better handle lambda formatting.
See I5e08687e696dd240402a2780158664b7113def0e for updated style.
See Iea0776aaa7edd483fa395e23de25ebf5a6288f71 for clang-18 enablement.
Change-Id: Iceec1dc95b6c908ec6c21fb40093de9dd18bf11a
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
diff --git a/http/http2_connection.hpp b/http/http2_connection.hpp
index 84e666f..1dcf87a 100644
--- a/http/http2_connection.hpp
+++ b/http/http2_connection.hpp
@@ -54,9 +54,8 @@
public:
HTTP2Connection(Adaptor&& adaptorIn, Handler* handlerIn,
std::function<std::string()>& getCachedDateStrF) :
- adaptor(std::move(adaptorIn)),
- ngSession(initializeNghttp2Session()), handler(handlerIn),
- getCachedDateStr(getCachedDateStrF)
+ adaptor(std::move(adaptorIn)), ngSession(initializeNghttp2Session()),
+ handler(handlerIn), getCachedDateStr(getCachedDateStrF)
{}
void start()
@@ -90,11 +89,10 @@
return 0;
}
- static ssize_t fileReadCallback(nghttp2_session* /* session */,
- int32_t streamId, uint8_t* buf,
- size_t length, uint32_t* dataFlags,
- nghttp2_data_source* /*source*/,
- void* userPtr)
+ static ssize_t
+ fileReadCallback(nghttp2_session* /* session */, int32_t streamId,
+ uint8_t* buf, size_t length, uint32_t* dataFlags,
+ nghttp2_data_source* /*source*/, void* userPtr)
{
self_type& self = userPtrToSelf(userPtr);
@@ -257,13 +255,13 @@
thisRes.setCompleteRequestHandler(
[this, streamId](Response& completeRes) {
- BMCWEB_LOG_DEBUG("res.completeRequestHandler called");
- if (sendResponse(completeRes, streamId) != 0)
- {
- close();
- return;
- }
- });
+ BMCWEB_LOG_DEBUG("res.completeRequestHandler called");
+ if (sendResponse(completeRes, streamId) != 0)
+ {
+ close();
+ return;
+ }
+ });
auto asyncResp =
std::make_shared<bmcweb::AsyncResp>(std::move(it->second.res));
if constexpr (!BMCWEB_INSECURE_DISABLE_AUTH)
@@ -322,10 +320,9 @@
return 0;
}
- static int onDataChunkRecvStatic(nghttp2_session* /* session */,
- uint8_t flags, int32_t streamId,
- const uint8_t* data, size_t len,
- void* userData)
+ static int onDataChunkRecvStatic(
+ nghttp2_session* /* session */, uint8_t flags, int32_t streamId,
+ const uint8_t* data, size_t len, void* userData)
{
BMCWEB_LOG_DEBUG("on_frame_recv_callback");
if (userData == nullptr)
@@ -333,8 +330,8 @@
BMCWEB_LOG_CRITICAL("user data was null?");
return NGHTTP2_ERR_CALLBACK_FAILURE;
}
- return userPtrToSelf(userData).onDataChunkRecvCallback(flags, streamId,
- data, len);
+ return userPtrToSelf(userData).onDataChunkRecvCallback(
+ flags, streamId, data, len);
}
int onFrameRecvCallback(const nghttp2_frame& frame)
@@ -457,11 +454,10 @@
return 0;
}
- static int onHeaderCallbackStatic(nghttp2_session* /* session */,
- const nghttp2_frame* frame,
- const uint8_t* name, size_t namelen,
- const uint8_t* value, size_t vallen,
- uint8_t /* flags */, void* userData)
+ static int onHeaderCallbackStatic(
+ nghttp2_session* /* session */, const nghttp2_frame* frame,
+ const uint8_t* name, size_t namelen, const uint8_t* value,
+ size_t vallen, uint8_t /* flags */, void* userData)
{
if (userData == nullptr)
{
diff --git a/http/http_body.hpp b/http/http_body.hpp
index 673058e..89baed2 100644
--- a/http/http_body.hpp
+++ b/http/http_body.hpp
@@ -155,8 +155,7 @@
public:
template <bool IsRequest, class Fields>
writer(boost::beast::http::header<IsRequest, Fields>& /*header*/,
- value_type& bodyIn) :
- body(bodyIn)
+ value_type& bodyIn) : body(bodyIn)
{}
static void init(boost::beast::error_code& ec)
@@ -234,8 +233,7 @@
public:
template <bool IsRequest, class Fields>
reader(boost::beast::http::header<IsRequest, Fields>& /*headers*/,
- value_type& body) :
- value(body)
+ value_type& body) : value(body)
{}
void init(const boost::optional<std::uint64_t>& contentLength,
diff --git a/http/http_client.hpp b/http/http_client.hpp
index 62e7df6..28aeb1c 100644
--- a/http/http_client.hpp
+++ b/http/http_client.hpp
@@ -120,8 +120,7 @@
PendingRequest(
boost::beast::http::request<bmcweb::HttpBody>&& reqIn,
const std::function<void(bool, uint32_t, Response&)>& callbackIn) :
- req(std::move(reqIn)),
- callback(callbackIn)
+ req(std::move(reqIn)), callback(callbackIn)
{}
};
@@ -321,8 +320,8 @@
{
state = ConnState::recvInProgress;
- parser_type& thisParser = parser.emplace(std::piecewise_construct,
- std::make_tuple());
+ parser_type& thisParser =
+ parser.emplace(std::piecewise_construct, std::make_tuple());
thisParser.body_limit(connPolicy->requestByteLimit);
@@ -635,9 +634,9 @@
const std::shared_ptr<ConnectionPolicy>& connPolicyIn,
const boost::urls::url_view_base& hostIn,
ensuressl::VerifyCertificate verifyCertIn, unsigned int connIdIn) :
- subId(idIn),
- connPolicy(connPolicyIn), host(hostIn), verifyCert(verifyCertIn),
- connId(connIdIn), ioc(iocIn), resolver(iocIn), conn(iocIn), timer(iocIn)
+ subId(idIn), connPolicy(connPolicyIn), host(hostIn),
+ verifyCert(verifyCertIn), connId(connIdIn), ioc(iocIn), resolver(iocIn),
+ conn(iocIn), timer(iocIn)
{
initializeConnection(host.scheme() == "https");
}
@@ -836,8 +835,7 @@
const std::shared_ptr<ConnectionPolicy>& connPolicyIn,
const boost::urls::url_view_base& destIPIn,
ensuressl::VerifyCertificate verifyCertIn) :
- ioc(iocIn),
- id(idIn), connPolicy(connPolicyIn), destIP(destIPIn),
+ ioc(iocIn), id(idIn), connPolicy(connPolicyIn), destIP(destIPIn),
verifyCert(verifyCertIn)
{
BMCWEB_LOG_DEBUG("Initializing connection pool for {}", id);
@@ -867,8 +865,7 @@
HttpClient() = delete;
explicit HttpClient(boost::asio::io_context& iocIn,
const std::shared_ptr<ConnectionPolicy>& connPolicyIn) :
- ioc(iocIn),
- connPolicy(connPolicyIn)
+ ioc(iocIn), connPolicy(connPolicyIn)
{}
HttpClient(const HttpClient&) = delete;
@@ -903,9 +900,9 @@
{
verify = "ssl no verify";
}
- std::string clientKey = std::format("{}{}://{}", verify,
- destUrl.scheme(),
- destUrl.encoded_host_and_port());
+ std::string clientKey =
+ std::format("{}{}://{}", verify, destUrl.scheme(),
+ destUrl.encoded_host_and_port());
auto pool = connectionPools.try_emplace(clientKey);
if (pool.first->second == nullptr)
{
diff --git a/http/http_connection.hpp b/http/http_connection.hpp
index e591455..265ab7e 100644
--- a/http/http_connection.hpp
+++ b/http/http_connection.hpp
@@ -64,9 +64,8 @@
Connection(Handler* handlerIn, boost::asio::steady_timer&& timerIn,
std::function<std::string()>& getCachedDateStrF,
Adaptor&& adaptorIn) :
- adaptor(std::move(adaptorIn)),
- handler(handlerIn), timer(std::move(timerIn)),
- getCachedDateStr(getCachedDateStrF)
+ adaptor(std::move(adaptorIn)), handler(handlerIn),
+ timer(std::move(timerIn)), getCachedDateStr(getCachedDateStrF)
{
initParser();
@@ -182,12 +181,12 @@
adaptor.async_handshake(boost::asio::ssl::stream_base::server,
[this, self(shared_from_this())](
const boost::system::error_code& ec) {
- if (ec)
- {
- return;
- }
- afterSslHandshake();
- });
+ if (ec)
+ {
+ return;
+ }
+ afterSslHandshake();
+ });
}
else
{
@@ -303,8 +302,8 @@
BMCWEB_LOG_DEBUG("Setting completion handler");
asyncResp->res.setCompleteRequestHandler(
[self(shared_from_this())](crow::Response& thisRes) {
- self->completeRequest(thisRes);
- });
+ self->completeRequest(thisRes);
+ });
bool isSse =
isContentTypeAllowed(req->getHeaderValue("Accept"),
http_helpers::ContentType::EventStream, false);
@@ -316,18 +315,18 @@
{
asyncResp->res.setCompleteRequestHandler(
[self(shared_from_this())](crow::Response& thisRes) {
- if (thisRes.result() != boost::beast::http::status::ok)
- {
- // When any error occurs before handle upgradation,
- // the result in response will be set to respective
- // error. By default the Result will be OK (200),
- // which implies successful handle upgrade. Response
- // needs to be sent over this connection only on
- // failure.
- self->completeRequest(thisRes);
- return;
- }
- });
+ if (thisRes.result() != boost::beast::http::status::ok)
+ {
+ // When any error occurs before handle upgradation,
+ // the result in response will be set to respective
+ // error. By default the Result will be OK (200),
+ // which implies successful handle upgrade. Response
+ // needs to be sent over this connection only on
+ // failure.
+ self->completeRequest(thisRes);
+ return;
+ }
+ });
handler->handleUpgrade(req, asyncResp, std::move(adaptor));
return;
}
@@ -495,73 +494,73 @@
[this,
self(shared_from_this())](const boost::system::error_code& ec,
std::size_t bytesTransferred) {
- BMCWEB_LOG_DEBUG("{} async_read_header {} Bytes", logPtr(this),
- bytesTransferred);
+ BMCWEB_LOG_DEBUG("{} async_read_header {} Bytes", logPtr(this),
+ bytesTransferred);
- if (ec)
- {
- cancelDeadlineTimer();
-
- if (ec == boost::beast::http::error::header_limit)
+ if (ec)
{
- BMCWEB_LOG_ERROR("{} Header field too large, closing",
- logPtr(this), ec.message());
+ cancelDeadlineTimer();
- res.result(boost::beast::http::status::
- request_header_fields_too_large);
- keepAlive = false;
+ if (ec == boost::beast::http::error::header_limit)
+ {
+ BMCWEB_LOG_ERROR("{} Header field too large, closing",
+ logPtr(this), ec.message());
+
+ res.result(boost::beast::http::status::
+ request_header_fields_too_large);
+ keepAlive = false;
+ doWrite();
+ return;
+ }
+ if (ec == boost::beast::http::error::end_of_stream)
+ {
+ BMCWEB_LOG_WARNING("{} End of stream, closing {}",
+ logPtr(this), ec);
+ hardClose();
+ return;
+ }
+
+ BMCWEB_LOG_DEBUG("{} Closing socket due to read error {}",
+ logPtr(this), ec.message());
+ gracefulClose();
+
+ return;
+ }
+
+ constexpr bool isTest =
+ std::is_same_v<Adaptor, boost::beast::test::stream>;
+
+ if constexpr (!BMCWEB_INSECURE_DISABLE_AUTH && !isTest)
+ {
+ boost::beast::http::verb method = parser->get().method();
+ userSession = crow::authentication::authenticate(
+ ip, res, method, parser->get().base(), mtlsSession);
+ }
+
+ std::string_view expect =
+ parser->get()[boost::beast::http::field::expect];
+ if (bmcweb::asciiIEquals(expect, "100-continue"))
+ {
+ res.result(boost::beast::http::status::continue_);
doWrite();
return;
}
- if (ec == boost::beast::http::error::end_of_stream)
+
+ if (!handleContentLengthError())
{
- BMCWEB_LOG_WARNING("{} End of stream, closing {}",
- logPtr(this), ec);
- hardClose();
return;
}
- BMCWEB_LOG_DEBUG("{} Closing socket due to read error {}",
- logPtr(this), ec.message());
- gracefulClose();
+ parser->body_limit(getContentLengthLimit());
- return;
- }
+ if (parser->is_done())
+ {
+ handle();
+ return;
+ }
- constexpr bool isTest =
- std::is_same_v<Adaptor, boost::beast::test::stream>;
-
- if constexpr (!BMCWEB_INSECURE_DISABLE_AUTH && !isTest)
- {
- boost::beast::http::verb method = parser->get().method();
- userSession = crow::authentication::authenticate(
- ip, res, method, parser->get().base(), mtlsSession);
- }
-
- std::string_view expect =
- parser->get()[boost::beast::http::field::expect];
- if (bmcweb::asciiIEquals(expect, "100-continue"))
- {
- res.result(boost::beast::http::status::continue_);
- doWrite();
- return;
- }
-
- if (!handleContentLengthError())
- {
- return;
- }
-
- parser->body_limit(getContentLengthLimit());
-
- if (parser->is_done())
- {
- handle();
- return;
- }
-
- doRead();
- });
+ doRead();
+ });
}
void doRead()
@@ -577,48 +576,50 @@
[this,
self(shared_from_this())](const boost::system::error_code& ec,
std::size_t bytesTransferred) {
- BMCWEB_LOG_DEBUG("{} async_read_some {} Bytes", logPtr(this),
- bytesTransferred);
+ BMCWEB_LOG_DEBUG("{} async_read_some {} Bytes", logPtr(this),
+ bytesTransferred);
- if (ec)
- {
- BMCWEB_LOG_ERROR("{} Error while reading: {}", logPtr(this),
- ec.message());
- if (ec == boost::beast::http::error::body_limit)
+ if (ec)
{
- if (handleContentLengthError())
+ BMCWEB_LOG_ERROR("{} Error while reading: {}", logPtr(this),
+ ec.message());
+ if (ec == boost::beast::http::error::body_limit)
{
- BMCWEB_LOG_CRITICAL("Body length limit reached, "
- "but no content-length "
- "available? Should never happen");
- res.result(
- boost::beast::http::status::internal_server_error);
- keepAlive = false;
- doWrite();
+ if (handleContentLengthError())
+ {
+ BMCWEB_LOG_CRITICAL(
+ "Body length limit reached, "
+ "but no content-length "
+ "available? Should never happen");
+ res.result(boost::beast::http::status::
+ internal_server_error);
+ keepAlive = false;
+ doWrite();
+ }
+ return;
}
+
+ gracefulClose();
return;
}
- gracefulClose();
- return;
- }
+ // If the user is logged in, allow them to send files
+ // incrementally one piece at a time. If authentication is
+ // disabled then there is no user session hence always allow to
+ // send one piece at a time.
+ if (userSession != nullptr)
+ {
+ cancelDeadlineTimer();
+ }
+ if (!parser->is_done())
+ {
+ doRead();
+ return;
+ }
- // If the user is logged in, allow them to send files incrementally
- // one piece at a time. If authentication is disabled then there is
- // no user session hence always allow to send one piece at a time.
- if (userSession != nullptr)
- {
cancelDeadlineTimer();
- }
- if (!parser->is_done())
- {
- doRead();
- return;
- }
-
- cancelDeadlineTimer();
- handle();
- });
+ handle();
+ });
}
void afterDoWrite(const std::shared_ptr<self_type>& /*self*/,
diff --git a/http/http_server.hpp b/http/http_server.hpp
index b22fae2..9fa927a 100644
--- a/http/http_server.hpp
+++ b/http/http_server.hpp
@@ -34,8 +34,7 @@
Server(Handler* handlerIn, boost::asio::ip::tcp::acceptor&& acceptorIn,
std::shared_ptr<boost::asio::ssl::context> adaptorCtxIn,
std::shared_ptr<boost::asio::io_context> io) :
- ioService(std::move(io)),
- acceptor(std::move(acceptorIn)),
+ ioService(std::move(io)), acceptor(std::move(acceptorIn)),
signals(*ioService, SIGINT, SIGTERM, SIGHUP), handler(handlerIn),
adaptorCtx(std::move(adaptorCtxIn))
{}
@@ -93,24 +92,24 @@
{
signals.async_wait(
[this](const boost::system::error_code& ec, int signalNo) {
- if (ec)
- {
- BMCWEB_LOG_INFO("Error in signal handler{}", ec.message());
- }
- else
- {
- if (signalNo == SIGHUP)
+ if (ec)
{
- BMCWEB_LOG_INFO("Receivied reload signal");
- loadCertificate();
- startAsyncWaitForSignal();
+ BMCWEB_LOG_INFO("Error in signal handler{}", ec.message());
}
else
{
- stop();
+ if (signalNo == SIGHUP)
+ {
+ BMCWEB_LOG_INFO("Receivied reload signal");
+ loadCertificate();
+ startAsyncWaitForSignal();
+ }
+ else
+ {
+ stop();
+ }
}
- }
- });
+ });
}
void stop()
diff --git a/http/logging.hpp b/http/logging.hpp
index 55f239f..e2b9fef 100644
--- a/http/logging.hpp
+++ b/http/logging.hpp
@@ -89,10 +89,10 @@
// throw Based on the documentation, it shouldn't throw, so long as none
// of the formatters throw, so unclear at this point why this try/catch
// is required, but add it to silence the static analysis tools.
- logLocation = std::format("[{} {}:{}] ", levelString, filename,
- loc.line());
- logLocation += std::format(std::move(format),
- std::forward<Args>(args)...);
+ logLocation =
+ std::format("[{} {}:{}] ", levelString, filename, loc.line());
+ logLocation +=
+ std::format(std::move(format), std::forward<Args>(args)...);
}
catch (const std::format_error& /*error*/)
{
@@ -173,21 +173,21 @@
};
template <typename... Args>
-BMCWEB_LOG_CRITICAL(std::format_string<Args...>, Args&&...)
- -> BMCWEB_LOG_CRITICAL<Args...>;
+BMCWEB_LOG_CRITICAL(std::format_string<Args...>,
+ Args&&...) -> BMCWEB_LOG_CRITICAL<Args...>;
template <typename... Args>
-BMCWEB_LOG_ERROR(std::format_string<Args...>, Args&&...)
- -> BMCWEB_LOG_ERROR<Args...>;
+BMCWEB_LOG_ERROR(std::format_string<Args...>,
+ Args&&...) -> BMCWEB_LOG_ERROR<Args...>;
template <typename... Args>
-BMCWEB_LOG_WARNING(std::format_string<Args...>, Args&&...)
- -> BMCWEB_LOG_WARNING<Args...>;
+BMCWEB_LOG_WARNING(std::format_string<Args...>,
+ Args&&...) -> BMCWEB_LOG_WARNING<Args...>;
template <typename... Args>
-BMCWEB_LOG_INFO(std::format_string<Args...>, Args&&...)
- -> BMCWEB_LOG_INFO<Args...>;
+BMCWEB_LOG_INFO(std::format_string<Args...>,
+ Args&&...) -> BMCWEB_LOG_INFO<Args...>;
template <typename... Args>
-BMCWEB_LOG_DEBUG(std::format_string<Args...>, Args&&...)
- -> BMCWEB_LOG_DEBUG<Args...>;
+BMCWEB_LOG_DEBUG(std::format_string<Args...>,
+ Args&&...) -> BMCWEB_LOG_DEBUG<Args...>;
diff --git a/http/mutual_tls.cpp b/http/mutual_tls.cpp
index 575897a..ec00de2 100644
--- a/http/mutual_tls.cpp
+++ b/http/mutual_tls.cpp
@@ -109,9 +109,9 @@
// Extract username contained in CommonName
commonName.resize(256, '\0');
- int length = X509_NAME_get_text_by_NID(X509_get_subject_name(peerCert),
- NID_commonName, commonName.data(),
- static_cast<int>(commonName.size()));
+ int length = X509_NAME_get_text_by_NID(
+ X509_get_subject_name(peerCert), NID_commonName, commonName.data(),
+ static_cast<int>(commonName.size()));
if (length <= 0)
{
BMCWEB_LOG_DEBUG("TLS cannot get common name to create session");
diff --git a/http/nghttp2_adapters.hpp b/http/nghttp2_adapters.hpp
index df230fe..61e45df 100644
--- a/http/nghttp2_adapters.hpp
+++ b/http/nghttp2_adapters.hpp
@@ -62,8 +62,8 @@
void setOnBeginHeadersCallback(
nghttp2_on_begin_headers_callback onBeginHeaders)
{
- nghttp2_session_callbacks_set_on_begin_headers_callback(ptr,
- onBeginHeaders);
+ nghttp2_session_callbacks_set_on_begin_headers_callback(
+ ptr, onBeginHeaders);
}
void setSendDataCallback(nghttp2_send_data_callback onSendData)
diff --git a/http/routing.hpp b/http/routing.hpp
index 5205a5b..6f42d22 100644
--- a/http/routing.hpp
+++ b/http/routing.hpp
@@ -213,8 +213,8 @@
if (reqUrl.starts_with(fragment))
{
- FindResult ret = findHelper(reqUrl.substr(fragment.size()),
- child, params);
+ FindResult ret =
+ findHelper(reqUrl.substr(fragment.size()), child, params);
if (ret.ruleIndex != 0U)
{
return {ret.ruleIndex, std::move(ret.params)};
@@ -532,8 +532,8 @@
perMethodIndex++)
{
// Make sure it's safe to deference the array at that index
- static_assert(maxVerbIndex <
- std::tuple_size_v<decltype(perMethods)>);
+ static_assert(
+ maxVerbIndex < std::tuple_size_v<decltype(perMethods)>);
FindRoute route = findRouteByPerMethod(req.url().encoded_path(),
perMethods[perMethodIndex]);
if (route.rule == nullptr)
@@ -584,11 +584,12 @@
// TODO(ed) This should be able to use std::bind_front, but it doesn't
// appear to work with the std::move on adaptor.
- validatePrivilege(req, asyncResp, rule,
- [req, &rule, asyncResp,
- adaptor = std::forward<Adaptor>(adaptor)]() mutable {
- rule.handleUpgrade(*req, asyncResp, std::move(adaptor));
- });
+ validatePrivilege(
+ req, asyncResp, rule,
+ [req, &rule, asyncResp,
+ adaptor = std::forward<Adaptor>(adaptor)]() mutable {
+ rule.handleUpgrade(*req, asyncResp, std::move(adaptor));
+ });
}
void handle(const std::shared_ptr<Request>& req,
@@ -657,8 +658,8 @@
validatePrivilege(
req, asyncResp, rule,
[req, asyncResp, &rule, params = std::move(params)]() {
- rule.handle(*req, asyncResp, params);
- });
+ rule.handle(*req, asyncResp, params);
+ });
}
void debugPrint()
diff --git a/http/utility.hpp b/http/utility.hpp
index 41b48e4..f2ac6e4 100644
--- a/http/utility.hpp
+++ b/http/utility.hpp
@@ -52,8 +52,8 @@
{
return 0;
}
- std::string_view tag = url.substr(urlSegmentIndex,
- urlIndex + 1 - urlSegmentIndex);
+ std::string_view tag =
+ url.substr(urlSegmentIndex, urlIndex + 1 - urlSegmentIndex);
if (tag == "<str>" || tag == "<string>")
{
@@ -239,8 +239,8 @@
auto getCodeValue = [](char c) {
auto code = static_cast<unsigned char>(c);
// Ensure we cannot index outside the bounds of the decoding array
- static_assert(std::numeric_limits<decltype(code)>::max() <
- decodingData.size());
+ static_assert(
+ std::numeric_limits<decltype(code)>::max() < decodingData.size());
return decodingData[code];
};
@@ -284,8 +284,8 @@
{ // non base64 character
return false;
}
- output += static_cast<char>(((base64code1 << 4) & 0xf0) |
- ((base64code2 >> 2) & 0x0f));
+ output += static_cast<char>(
+ ((base64code1 << 4) & 0xf0) | ((base64code2 >> 2) & 0x0f));
}
if (++i < inputLength)
@@ -310,9 +310,8 @@
namespace details
{
-inline boost::urls::url
- appendUrlPieces(boost::urls::url& url,
- const std::initializer_list<std::string_view> args)
+inline boost::urls::url appendUrlPieces(
+ boost::urls::url& url, const std::initializer_list<std::string_view> args)
{
for (std::string_view arg : args)
{
diff --git a/http/websocket.hpp b/http/websocket.hpp
index 7e38302..be650ae 100644
--- a/http/websocket.hpp
+++ b/http/websocket.hpp
@@ -62,8 +62,7 @@
messageExHandlerIn,
std::function<void(Connection&, const std::string&)> closeHandlerIn,
std::function<void(Connection&)> errorHandlerIn) :
- uri(urlViewIn),
- ws(std::move(adaptorIn)), inBuffer(inString, 131088),
+ uri(urlViewIn), ws(std::move(adaptorIn)), inBuffer(inString, 131088),
openHandler(std::move(openHandlerIn)),
messageHandler(std::move(messageHandlerIn)),
messageExHandler(std::move(messageExHandlerIn)),
@@ -93,36 +92,37 @@
ws.set_option(boost::beast::websocket::stream_base::decorator(
[session{session},
protocolHeader](boost::beast::websocket::response_type& m) {
- if constexpr (!BMCWEB_INSECURE_DISABLE_CSRF)
- {
- if (session != nullptr)
+ if constexpr (!BMCWEB_INSECURE_DISABLE_CSRF)
{
- // use protocol for csrf checking
- if (session->cookieAuth &&
- !bmcweb::constantTimeStringCompare(protocolHeader,
- session->csrfToken))
+ if (session != nullptr)
{
- BMCWEB_LOG_ERROR("Websocket CSRF error");
- m.result(boost::beast::http::status::unauthorized);
- return;
+ // use protocol for csrf checking
+ if (session->cookieAuth &&
+ !bmcweb::constantTimeStringCompare(
+ protocolHeader, session->csrfToken))
+ {
+ BMCWEB_LOG_ERROR("Websocket CSRF error");
+ m.result(boost::beast::http::status::unauthorized);
+ return;
+ }
}
}
- }
- if (!protocolHeader.empty())
- {
- m.insert(bf::sec_websocket_protocol, protocolHeader);
- }
+ if (!protocolHeader.empty())
+ {
+ m.insert(bf::sec_websocket_protocol, protocolHeader);
+ }
- m.insert(bf::strict_transport_security, "max-age=31536000; "
- "includeSubdomains; "
- "preload");
- m.insert(bf::pragma, "no-cache");
- m.insert(bf::cache_control, "no-Store,no-Cache");
- m.insert("Content-Security-Policy", "default-src 'self'");
- m.insert("X-XSS-Protection", "1; "
- "mode=block");
- m.insert("X-Content-Type-Options", "nosniff");
- }));
+ m.insert(bf::strict_transport_security,
+ "max-age=31536000; "
+ "includeSubdomains; "
+ "preload");
+ m.insert(bf::pragma, "no-cache");
+ m.insert(bf::cache_control, "no-Store,no-Cache");
+ m.insert("Content-Security-Policy", "default-src 'self'");
+ m.insert("X-XSS-Protection", "1; "
+ "mode=block");
+ m.insert("X-Content-Type-Options", "nosniff");
+ }));
// Make a pointer to keep the req alive while we accept it.
using Body = boost::beast::http::request<bmcweb::HttpBody>;
@@ -157,23 +157,24 @@
ws.async_write(boost::asio::buffer(msg),
[weak(weak_from_this()), onDone{std::move(onDone)}](
const boost::beast::error_code& ec, size_t) {
- std::shared_ptr<Connection> self = weak.lock();
- if (!self)
- {
- BMCWEB_LOG_ERROR("Connection went away");
- return;
- }
+ std::shared_ptr<Connection> self = weak.lock();
+ if (!self)
+ {
+ BMCWEB_LOG_ERROR("Connection went away");
+ return;
+ }
- // Call the done handler regardless of whether we
- // errored, but before we close things out
- onDone();
+ // Call the done handler regardless of whether we
+ // errored, but before we close things out
+ onDone();
- if (ec)
- {
- BMCWEB_LOG_ERROR("Error in ws.async_write {}", ec);
- self->close("write error");
- }
- });
+ if (ec)
+ {
+ BMCWEB_LOG_ERROR("Error in ws.async_write {}",
+ ec);
+ self->close("write error");
+ }
+ });
}
void sendText(std::string_view msg) override
@@ -189,16 +190,16 @@
ws.async_close(
{boost::beast::websocket::close_code::normal, msg},
[self(shared_from_this())](const boost::system::error_code& ec) {
- if (ec == boost::asio::error::operation_aborted)
- {
- return;
- }
- if (ec)
- {
- BMCWEB_LOG_ERROR("Error closing websocket {}", ec);
- return;
- }
- });
+ if (ec == boost::asio::error::operation_aborted)
+ {
+ return;
+ }
+ if (ec)
+ {
+ BMCWEB_LOG_ERROR("Error closing websocket {}", ec);
+ return;
+ }
+ });
}
boost::urls::url_view url() override
@@ -315,16 +316,16 @@
// this message handler overrides the normal message handler
messageExHandler(*this, inString, MessageType::Binary,
[this, self(shared_from_this()), bytesRead]() {
- if (self == nullptr)
- {
- return;
- }
+ if (self == nullptr)
+ {
+ return;
+ }
- inBuffer.consume(bytesRead);
- inString.clear();
+ inBuffer.consume(bytesRead);
+ inString.clear();
- doRead();
- });
+ doRead();
+ });
return;
}