Skip to content

Commit

Permalink
Coding style
Browse files Browse the repository at this point in the history
  • Loading branch information
Tectu committed Dec 27, 2023
1 parent 817061c commit f3c35ff
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 68 deletions.
65 changes: 0 additions & 65 deletions lib/malloy/core/http/request.hpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
#pragma once

#include "cookie.hpp"
#include "types.hpp"

#include <boost/beast/http/string_body.hpp>

#include <unordered_map>

namespace malloy::http
{

Expand Down Expand Up @@ -51,22 +48,6 @@ namespace malloy::http

// Underlying
msg_t::operator=(std::move(raw));

// Cookies
{
const auto &[begin, end] = msg_t::base().equal_range(field::cookie);
for (auto it = begin; it != end; it++) {
const auto &str = it->value();

const auto &sep_pos = it->value().find('=');
if (sep_pos == std::string::npos)
continue;

std::string key{str.substr(0, sep_pos)};
std::string value{str.substr(sep_pos + 1)};
m_cookies.insert_or_assign(std::move(key), std::move(value));
}
}
}

/**
Expand Down Expand Up @@ -119,54 +100,8 @@ namespace malloy::http
return m_port;
}

/**
* Returns the request's cookies.
*
* @return The cookies.
*/
[[nodiscard]]
std::unordered_map<std::string, std::string>
cookies() const noexcept
{
return m_cookies;
}

/**
* Checks whether a particular cookie is present.
*
* @return Whether the specified cookie is present.
*/
[[nodiscard]]
bool
has_cookie(const std::string& name) const
{
return m_cookies.contains(name);
}

/**
* Gets the value of a cookie.
*/
[[nodiscard]]
std::string_view
cookie(const std::string_view& name) const
{
const auto& it = std::find_if(
std::cbegin(m_cookies),
std::cend(m_cookies),
[&name](const auto& pair) {
return pair.first == name;
}
);

if (it == std::cend(m_cookies))
return { };

return it->second;
}

private:
std::uint16_t m_port = 0;
std::unordered_map<std::string, std::string> m_cookies;
};
}

Expand Down
2 changes: 2 additions & 0 deletions lib/malloy/core/http/response.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ namespace malloy::http
/**
* Adds a cookie.
*
* @note This adds to the `Set-Cookie` field.
*
* @param c The cookie.
*/
void
Expand Down
9 changes: 6 additions & 3 deletions lib/malloy/server/routing/router.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,8 @@ namespace malloy::server
bool isWebsocket = false,
typename Derived,
typename Connection>
void handle_request(
void
handle_request(
const std::filesystem::path& doc_root,
const req_generator<Derived>& req,
Connection&& connection
Expand Down Expand Up @@ -525,7 +526,8 @@ namespace malloy::server
* @param connection The HTTP connection.
*/
template<typename Derived>
void handle_http_request(
void
handle_http_request(
const std::filesystem::path&,
const req_generator<Derived>& req,
const http::connection_t& connection
Expand Down Expand Up @@ -570,7 +572,8 @@ namespace malloy::server
* @param connection The WebSocket connection.
*/
template<typename Derived>
void handle_ws_request(
void
handle_ws_request(
const req_generator<Derived>& gen,
const std::shared_ptr<websocket::connection>& connection
)
Expand Down

0 comments on commit f3c35ff

Please sign in to comment.