diff options
author | Ed Tanous <edtanous@google.com> | 2022-05-31 18:59:27 +0300 |
---|---|---|
committer | Ed Tanous <ed@tanous.net> | 2022-06-01 19:10:35 +0300 |
commit | 002d39b4a7a5ed7166e2acad84e0943c3def9492 (patch) | |
tree | 4307dd5161ec9779d59308a9b933e408cc2c6ca7 /http/websocket.hpp | |
parent | 62c416fb0d2f62e09d7f60754ff359ac2389e749 (diff) | |
download | bmcweb-002d39b4a7a5ed7166e2acad84e0943c3def9492.tar.xz |
Try to fix the lambda formatting issue
clang-tidy has a setting, LambdaBodyIndentation, which it says:
"For callback-heavy code, it may improve readability to have the
signature indented two levels and to use OuterScope."
bmcweb is very callback heavy code. Try to enable it and see if that
improves things. There are many cases where the length of a lambda call
will change, and reindent the entire lambda function. This is really
bad for code reviews, as it's difficult to see the lines changed. This
commit should resolve it. This does have the downside of reindenting a
lot of functions, which is unfortunate, but probably worth it in the
long run.
All changes except for the .clang-format file were made by the robot.
Tested: Code compiles, whitespace changes only.
Signed-off-by: Ed Tanous <edtanous@google.com>
Change-Id: Ib4aa2f1391fada981febd25b67dcdb9143827f43
Diffstat (limited to 'http/websocket.hpp')
-rw-r--r-- | http/websocket.hpp | 141 |
1 files changed, 70 insertions, 71 deletions
diff --git a/http/websocket.hpp b/http/websocket.hpp index b2c24c403a..9a735fdabf 100644 --- a/http/websocket.hpp +++ b/http/websocket.hpp @@ -108,34 +108,34 @@ class ConnectionImpl : public Connection boost::beast::websocket::response_type& m) { #ifndef BMCWEB_INSECURE_DISABLE_CSRF_PREVENTION - if (session != nullptr) + if (session != nullptr) + { + // use protocol for csrf checking + if (session->cookieAuth && + !crow::utility::constantTimeStringCompare( + protocol, session->csrfToken)) { - // use protocol for csrf checking - if (session->cookieAuth && - !crow::utility::constantTimeStringCompare( - protocol, session->csrfToken)) - { - BMCWEB_LOG_ERROR << "Websocket CSRF error"; - m.result(boost::beast::http::status::unauthorized); - return; - } + BMCWEB_LOG_ERROR << "Websocket CSRF error"; + m.result(boost::beast::http::status::unauthorized); + return; } + } #endif - if (!protocol.empty()) - { - m.insert(bf::sec_websocket_protocol, protocol); - } + if (!protocol.empty()) + { + m.insert(bf::sec_websocket_protocol, protocol); + } - 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"); + })); // Perform the websocket upgrade ws.async_accept(req, [this, self(shared_from_this())]( @@ -182,15 +182,15 @@ class ConnectionImpl : public Connection ws.async_close( {boost::beast::websocket::close_code::normal, msg}, [self(shared_from_this())](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; + } }); } @@ -211,27 +211,27 @@ class ConnectionImpl : public Connection ws.async_read(inBuffer, [this, self(shared_from_this())]( boost::beast::error_code ec, std::size_t bytesRead) { - if (ec) - { - if (ec != boost::beast::websocket::error::closed) - { - BMCWEB_LOG_ERROR << "doRead error " << ec; - } - if (closeHandler) - { - std::string_view reason = ws.reason().reason; - closeHandler(*this, std::string(reason)); - } - return; - } - if (messageHandler) - { - messageHandler(*this, inString, ws.got_text()); - } - inBuffer.consume(bytesRead); - inString.clear(); - doRead(); - }); + if (ec) + { + if (ec != boost::beast::websocket::error::closed) + { + BMCWEB_LOG_ERROR << "doRead error " << ec; + } + if (closeHandler) + { + std::string_view reason = ws.reason().reason; + closeHandler(*this, std::string(reason)); + } + return; + } + if (messageHandler) + { + messageHandler(*this, inString, ws.got_text()); + } + inBuffer.consume(bytesRead); + inString.clear(); + doRead(); + }); } void doWrite() @@ -252,23 +252,22 @@ class ConnectionImpl : public Connection ws.async_write(boost::asio::buffer(outBuffer.front()), [this, self(shared_from_this())]( boost::beast::error_code ec, std::size_t) { - doingWrite = false; - outBuffer.erase(outBuffer.begin()); - if (ec == boost::beast::websocket::error::closed) - { - // Do nothing here. doRead handler will call the - // closeHandler. - close("Write error"); - return; - } - if (ec) - { - BMCWEB_LOG_ERROR << "Error in ws.async_write " - << ec; - return; - } - doWrite(); - }); + doingWrite = false; + outBuffer.erase(outBuffer.begin()); + if (ec == boost::beast::websocket::error::closed) + { + // Do nothing here. doRead handler will call the + // closeHandler. + close("Write error"); + return; + } + if (ec) + { + BMCWEB_LOG_ERROR << "Error in ws.async_write " << ec; + return; + } + doWrite(); + }); } private: |