Thoth
A functional, expressive, asynchronous C++26 webdev library
Loading...
Searching...
No Matches
PutMethod.hpp
Go to the documentation of this file.
1#pragma once
3
4namespace Thoth::Http {
5 struct PutMethod {
6 static constexpr std::string_view MethodName() { return "PUT"; }
7 static constexpr bool IsSafe() { return false; }
8 static constexpr bool IsIdempotent() { return true; }
9
11 return {};
12 }
13
14 static WebResultOper ValidateResponse(StatusCodeEnum statusCode, string_view body, const Url&, const Headers& headers) {
15 if ((statusCode == StatusCodeEnum::NO_CONTENT || statusCode == StatusCodeEnum::NOT_MODIFIED) && !body.empty())
16 return std::unexpected{ StatusCodeEnum::BAD_GATEWAY };
17
18 if (statusCode == StatusCodeEnum::CREATED && !headers.Exists("Location"))
19 return std::unexpected{ StatusCodeEnum::BAD_GATEWAY };
20
21 return {};
22 }
23 };
24
25 static_assert(MethodConcept<PutMethod>);
26}
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 PutMethod.hpp:5
static constexpr bool IsSafe()
Definition PutMethod.hpp:7
static constexpr bool IsIdempotent()
Definition PutMethod.hpp:8
static constexpr std::string_view MethodName()
Definition PutMethod.hpp:6
static WebResultOper ValidateRequest(string_view, const Url &, const Headers &)
Definition PutMethod.hpp:10
static WebResultOper ValidateResponse(StatusCodeEnum statusCode, string_view body, const Url &, const Headers &headers)
Definition PutMethod.hpp:14
Definition Url.hpp:10