Thoth
A functional, expressive, asynchronous C++26 webdev library
Loading...
Searching...
No Matches
GetMethod.hpp
Go to the documentation of this file.
1#pragma once
3
4namespace Thoth::Http {
5 struct GetMethod {
6 static constexpr std::string_view MethodName() { return "GET"; }
7 static constexpr bool IsSafe() { return true; }
8 static constexpr bool IsIdempotent() { return true; }
9
10 static WebResultOper ValidateRequest(string_view body, const Url&, const Headers&) {
11 if (!body.empty())
12 return std::unexpected{ StatusCodeEnum::BAD_REQUEST };
13 return {};
14 }
15
16 static WebResultOper ValidateResponse(StatusCodeEnum statusCode, string_view body, const Url&, const Headers&) {
17 if ((statusCode == StatusCodeEnum::NO_CONTENT || statusCode == StatusCodeEnum::NOT_MODIFIED) && !body.empty())
18 return std::unexpected{ StatusCodeEnum::BAD_GATEWAY };
19 return {};
20 }
21 };
22
23 static_assert(MethodConcept<GetMethod>);
24}
Definition Client.hpp:12
StatusCodeEnum
Definition StatusCodeEnum.hpp:7
WebResult< std::monostate > WebResultOper
Definition StatusCodeEnum.hpp:111
std::string_view string_view
Definition Url.hpp:7
Definition GetMethod.hpp:5
static WebResultOper ValidateResponse(StatusCodeEnum statusCode, string_view body, const Url &, const Headers &)
Definition GetMethod.hpp:16
static constexpr bool IsIdempotent()
Definition GetMethod.hpp:8
static constexpr std::string_view MethodName()
Definition GetMethod.hpp:6
static constexpr bool IsSafe()
Definition GetMethod.hpp:7
static WebResultOper ValidateRequest(string_view body, const Url &, const Headers &)
Definition GetMethod.hpp:10
This class stores the headers from HTTP.
Definition Headers.hpp:29
Definition Url.hpp:10