4#include "Stroika/Frameworks/StroikaPreComp.h"
9#include "Stroika/Foundation/IO/Network/HTTP/ClientErrorException.h"
11#include "Stroika/Frameworks/WebService/Server/Basic.h"
13#include "VariantValue.h"
21using namespace Stroika::Frameworks;
22using namespace Stroika::Frameworks::WebService;
23using namespace Stroika::Frameworks::WebService::Server;
36 if (
auto query = url.GetQuery ()) {
37 Mapping<String, String> unconverted = query->GetMap ();
38 unconverted.Apply ([&] (const KeyValuePair<String, String>& kvp) { result.Add (kvp.fKey, VariantValue{kvp.fValue}); });
51 static const InternetMediaType kDefaultCT_ = DataExchange::InternetMediaTypes::kJSON;
52 if (bodyContentType.value_or (kDefaultCT_) == DataExchange::InternetMediaTypes::kJSON) {
71 if (not inData.
empty ()) {
72 DataExchange::VariantValue bodyObj = Variant::JSON::Reader{}.Read (inData);
73 switch (bodyObj.GetType ()) {
74 case DataExchange::VariantValue::eMap:
77 case DataExchange::VariantValue::eNull:
85 result.
AddAll (PickoutParamValuesFromURL (request));
99 PickoutParamValuesFromBody (request).Apply ([&] (
auto i) { result.
Add (i.fKey, i.fValue); });
126 return ClientErrorException::TreatExceptionsAsClientError ([&] () {
return request.
GetBodyVariantValue (); });
131 return ClientErrorException::TreatExceptionsAsClientError ([&] () {
133 if (
auto query = request.
url ().GetQuery ()) {
134 Mapping<String, String> unconverted = query->GetMap ();
135 unconverted.Apply ([&] (const KeyValuePair<String, String>& kvp) { result.Add (kvp.fKey, VariantValue{kvp.fValue}); });
137 if (result.
empty ()) {
146 return ClientErrorException::TreatExceptionsAsClientError ([&] () {
156 if (requestBody.GetType () != VariantValue::eMap or urlBody.GetType () != VariantValue::eMap) {
176 if (
auto o = paramValues.
Lookup (name)) {
177 result += DataExchange::VariantValue{*o};
191void Server::VariantValue::WriteResponse (Response& response,
const WebServiceMethodDescription& webServiceDescription,
const Memory::BLOB& responseValue)
193 if (webServiceDescription.fResponseType) {
194 response.contentType = *webServiceDescription.fResponseType;
195 response.write (responseValue);
202void Server::VariantValue::WriteResponse (Response& response,
const WebServiceMethodDescription& webServiceDescription,
const VariantValue& responseValue)
205 Require (not webServiceDescription.fResponseType.has_value () or
206 (webServiceDescription.fResponseType == DataExchange::InternetMediaTypes::kJSON or
207 webServiceDescription.fResponseType == DataExchange::InternetMediaTypes::kText_PLAIN));
208 if (webServiceDescription.fResponseType) {
209 if (registry.
IsA (InternetMediaTypes::kJSON, *webServiceDescription.fResponseType)) {
210 response.contentType = *webServiceDescription.fResponseType;
213 else if (registry.
IsA (InternetMediaTypes::Wildcards::kText, *webServiceDescription.fResponseType)) {
214 response.contentType = *webServiceDescription.fResponseType;
#define RequireNotReached()
#define WeakAssert(c)
A WeakAssert() is for things that aren't guaranteed to be true, but are overwhelmingly likely to be t...
String is like std::u32string, except it is much easier to use, often much more space efficient,...
nonvirtual CONTAINER_OF_Key_T As() const
nonvirtual bool Add(ArgByValueType< key_type > key, ArgByValueType< mapped_type > newElt, AddReplaceMode addReplaceMode=AddReplaceMode::eAddReplaces)
nonvirtual optional< mapped_type > Lookup(ArgByValueType< key_type > key) const
nonvirtual unsigned int AddAll(ITERABLE_OF_ADDABLE &&items, AddReplaceMode addReplaceMode=AddReplaceMode::eAddReplaces)
nonvirtual mapped_type LookupValue(ArgByValueType< key_type > key, ArgByValueType< mapped_type > defaultValue=mapped_type{}) const
A generalization of a vector: a container whose elements are keyed by the natural numbers.
nonvirtual Memory::BLOB WriteAsBLOB(const VariantValue &v) const
Simple variant-value (case variant union) object, with (variant) basic types analogous to a value in ...
nonvirtual RETURNTYPE As() const
ClientErrorException is to capture exceptions caused by a bad (e.g ill-formed) request.
static RESULT_TYPE TreatExceptionsAsClientError(FUNCTION &&f)
Common::Property< URI > url
nonvirtual bool empty() const
Iterable<T> is a base class for containers which easily produce an Iterator<T> to traverse them.
nonvirtual void Apply(const function< void(ArgByValueType< T > item)> &doToElement, Execution::SequencePolicy seq=Execution::SequencePolicy::eDEFAULT) const
Run the argument function (or lambda) on each element of the container.
nonvirtual RESULT_CONTAINER Map(ELEMENT_MAPPER &&elementMapper) const
functional API which iterates over all members of an Iterable, applies a map function to each element...
nonvirtual bool empty() const
Returns true iff size() == 0.
this represents a HTTP request object for the WebServer module
nonvirtual Memory::BLOB GetBody()
nonvirtual DataExchange::VariantValue GetBodyVariantValue()
void Throw(T &&e2Throw)
identical to builtin C++ 'throw' except that it does helpful, type dependent DbgTrace() messages firs...