Thoth
A functional, expressive, asynchronous C++26 webdev library
Loading...
Searching...
No Matches
OptionsMethod.hpp
Go to the documentation of this file.
1#pragma once
3
4namespace Thoth::Http {
5 struct OptionsMethod {
6 static constexpr std::string_view MethodName() { return "OPTIONS"; }
7 static constexpr bool IsSafe() { return true; }
8 static constexpr bool IsIdempotent() { return true; }
9
10 static WebResultOper ValidateRequest(string_view body, const Url& url, const Headers& 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& url, const Headers& headers) {
17 if ((statusCode == StatusCodeEnum::NO_CONTENT || statusCode == StatusCodeEnum::NOT_MODIFIED) && !body.empty())
18 return std::unexpected{ StatusCodeEnum::BAD_GATEWAY };
19
20
21 if (statusCode == StatusCodeEnum::OK && !headers.Exists("Allow"))
22 return std::unexpected{ StatusCodeEnum::BAD_GATEWAY };
23
24 return {};
25 }
26 };
27
28 static_assert(MethodConcept<OptionsMethod>);
29}
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
This class stores the headers from HTTP.
Definition Headers.hpp:29
bool Exists(HeaderKeyRef key) const
check if a key exists.
Definition OptionsMethod.hpp:5
static WebResultOper ValidateResponse(StatusCodeEnum statusCode, string_view body, const Url &url, const Headers &headers)
Definition OptionsMethod.hpp:16
static constexpr bool IsSafe()
Definition OptionsMethod.hpp:7
static WebResultOper ValidateRequest(string_view body, const Url &url, const Headers &headers)
Definition OptionsMethod.hpp:10
static constexpr bool IsIdempotent()
Definition OptionsMethod.hpp:8
static constexpr std::string_view MethodName()
Definition OptionsMethod.hpp:6
Definition Url.hpp:10