blob: b0bad07b7e276ab208ea9d630ce678b2290f2b61 [file] [log] [blame]
#include "http_request.hpp"
#include <string_view>
#include <system_error>
#include <utility>
#include "absl/log/log.h"
namespace crow {
Request::Request(
boost::beast::http::request<boost::beast::http::string_body> reqIn,
std::error_code& ec)
: req(std::move(reqIn)) {
if (!setUrlInfo()) {
ec = std::make_error_code(std::errc::invalid_argument);
}
LOG(INFO) << "=> HTTP: Request: path: target: " << this->target();
}
Request::Request(std::string_view bodyIn, std::error_code& ec)
: req({}, bodyIn) {
if (!setUrlInfo()) {
ec = std::make_error_code(std::errc::invalid_argument);
}
LOG(INFO) << "=> HTTP: Request: path: target: " << this->target();
}
bool Request::setUrlInfo() {
auto result = boost::urls::parse_relative_ref(target());
if (!result) {
return false;
}
urlBase = *result;
return true;
}
} // namespace crow