TASK00 - Авторизация и регистрация

This commit is contained in:
Антон
2025-06-06 19:59:51 +03:00
parent 8cedc84947
commit 321116ac90
13 changed files with 627 additions and 396 deletions
+46 -5
View File
@@ -1,9 +1,21 @@
#include <iostream>
#include <string>
#include <boost/algorithm/string.hpp>
#include <boost/format.hpp>
#include "helpers.h"
namespace uad {
boost::beast::string_view MimeType(boost::beast::string_view path) {
using namespace std;
using namespace boost;
namespace uad
{
boost::beast::string_view MimeType(boost::beast::string_view path)
{
using boost::beast::iequals;
auto const ext = [&path] {
auto const ext = [&path]
{
auto const pos = path.rfind(".");
if (pos == boost::beast::string_view::npos)
return boost::beast::string_view{};
@@ -54,7 +66,8 @@ boost::beast::string_view MimeType(boost::beast::string_view path) {
return "application/text";
}
std::string PathCat(boost::beast::string_view base, boost::beast::string_view path){
std::string PathCat(boost::beast::string_view base, boost::beast::string_view path)
{
if (base.empty())
return std::string(path);
std::string result(base);
@@ -63,7 +76,7 @@ std::string PathCat(boost::beast::string_view base, boost::beast::string_view pa
if (result.back() == path_separator)
result.resize(result.size() - 1);
result.append(path.data(), path.size());
for (auto &c : result)
for (auto& c : result)
if (c == '/')
c = path_separator;
#else
@@ -74,4 +87,32 @@ std::string PathCat(boost::beast::string_view base, boost::beast::string_view pa
#endif
return result;
}
void Fail(boost::beast::error_code ec, char const* what)
{
std::cerr << what << ": " << ec.message() << "\n";
}
std::string ToHex(std::byte* src, size_t len)
{
if (!src || !len)
return "";
string ret;
ret.reserve(len * 2);
format formatter = format("%02X");
for (size_t i = 0; i < len; ++i)
{
byte target_byte = src[i];
formatter % static_cast<int32_t>(target_byte);
ret += formatter.str();
formatter.clear();
}
return ret;
}
} // namespace uad
+9 -2
View File
@@ -1,7 +1,14 @@
#pragma once
#include <boost/beast.hpp>
namespace uad {
namespace uad
{
boost::beast::string_view MimeType(boost::beast::string_view path);
std::string PathCat(boost::beast::string_view base, boost::beast::string_view path);
}
void Fail(boost::beast::error_code ec, char const* what);
std::string ToHex(std::byte* src, size_t len);
} // namespace uad