Thoth
A functional, expressive, asynchronous C++26 webdev library
Loading...
Searching...
No Matches
TraceMethod.hpp
Go to the documentation of this file.
1#pragma once
3
4namespace Thoth::Http {
5 struct TraceMethod {
6 static constexpr std::string_view MethodName() { return "TRACE"; }
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& headers) {
17 string str;
18 auto ref{ &str };
19
20 if (statusCode == StatusCodeEnum::OK)
21 if (*headers.Get("Content-Type").value_or(ref) != "message/http")
22 return std::unexpected{ StatusCodeEnum::BAD_GATEWAY };
23
24
25 if ((statusCode == StatusCodeEnum::NO_CONTENT || statusCode == StatusCodeEnum::NOT_MODIFIED) && !body.empty())
26 return std::unexpected{ StatusCodeEnum::BAD_GATEWAY };
27
28 return {};
29 }
30 };
31
32 static_assert(MethodConcept<TraceMethod>);
33}
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
std::optional< HeaderValue * > Get(HeaderKeyRef key)
Get the reference of a key but don't create if it not exists.
Definition TraceMethod.hpp:5
static WebResultOper ValidateRequest(string_view body, const Url &, const Headers &)
Definition TraceMethod.hpp:10
static constexpr std::string_view MethodName()
Definition TraceMethod.hpp:6
static constexpr bool IsIdempotent()
Definition TraceMethod.hpp:8
static constexpr bool IsSafe()
Definition TraceMethod.hpp:7
static WebResultOper ValidateResponse(StatusCodeEnum statusCode, string_view body, const Url &, const Headers &headers)
Definition TraceMethod.hpp:16
Definition Url.hpp:10