4#include "Stroika/Frameworks/StroikaPreComp.h"
9#include "Stroika/Foundation/Containers/Mapping.h"
13#include "Stroika/Foundation/IO/Network/HTTP/ClientErrorException.h"
22using namespace Stroika::Frameworks;
23using namespace Stroika::Frameworks::WebService;
35void WebService::Server::ExpectedMethod (
const Request& request,
const Set<String>& methods,
const optional<String>& fromInMessage)
37#if USE_NOISY_TRACE_IN_THIS_MODULE_
39 "WebService::Server::ExpectedMethod",
"request={}, methods={}, fromInMessage={}"_f, request, methods, fromInMessage)};
41 if (not methods.Contains (request.httpMethod ())) {
43 request.httpMethod (), (fromInMessage ? (L
" from '"sv + *fromInMessage + L
"'"sv).As<wstring> ().c_str () : L
""), methods)});
47void WebService::Server::ExpectedMethod (
const Request& request,
const Iterable<String>& methods,
const optional<String>& fromInMessage)
49 ExpectedMethod (request,
Set<String>{methods}, fromInMessage);
52void WebService::Server::ExpectedMethod (
const Request& request,
const WebServiceMethodDescription& wsMethodDescription)
54 if (wsMethodDescription.fAllowedMethods) {
55 ExpectedMethod (request, *wsMethodDescription.fAllowedMethods, wsMethodDescription.fOperation);
64const String WebService::Server::DocsOptions::kDefaultCSSSection =
65 "div.mainDocs {margin-left: .3in; margin-right: .3in; }\n"
66 "div.mainDocs div { padding-top: 6pt; padding-bottom: 6pt; }\n"
67 "div.OpenAPI { padding-top: 12pt; padding-bottom: 12pt; }\n"
68 "div.curlExample {margin-left: .3in; margin-top: .1in; margin-bottom:.1in; font-family: \"Courier New\", Courier, \"Lucida Sans "
69 "Typewriter\", \"Lucida Typewriter\", monospace; font-size: 9pt; font-weight: bold;}\n"
70 "div.curlExample div { padding-top: 2pt; padding-bottom: 2pt; }\n"
71 "div.introduction div { padding-top: 2pt; padding-bottom: 2pt; }\n"sv;
75 response.contentType = DataExchange::InternetMediaTypes::kHTML;
76 response.writeln (
"<html>"sv);
77 response.writeln (
"<style type=\"text/css\">"sv);
78 response.writeln (docsOptions.fCSSSection);
79 response.writeln (
"</style>"sv);
80 response.writeln (
"<body>"sv);
81 response.write (
"<h1>{}</h1>"_f, docsOptions.fH1Text);
82 response.write (
"<div class='introduction'>{}</div>\n"_f, docsOptions.fIntroductoryText);
84 if (docsOptions.fOpenAPISpecificationURI) {
85 response.write (
"<div class='OpenAPI'>Download <a href={}>OpenAPI File</a></div>\n"_f, *docsOptions.fOpenAPISpecificationURI);
87 response.writeln (
"<ul>"sv);
88 auto substVars = [&] (
const String& origStr) {
90 for (
const auto& i : docsOptions.fVariables2Substitute) {
91 str = str.
ReplaceAll (
"{{" + i.fKey +
"}}", i.fValue);
95 auto writeDocs = [&] (
const String& methodName,
const String& docs,
const String& exampleCall) {
96 response.writeln (
"<li>"sv);
97 response.write (
"<a href=\"/{}\">{}</a>"_f, methodName, methodName);
98 response.write (
"<div class='mainDocs'>{}</div>"_f, docs);
99 response.write (
"<div class='curlExample'>{}</div>"_f, exampleCall);
100 response.writeln (
"</li>"sv);
102 for (
const WebServiceMethodDescription& i : operations) {
104 if (i.fDetailedDocs) {
105 i.fDetailedDocs->Apply ([&] (
const String& i) { tmpDocs <<
"<div>"sv << substVars (i) <<
"</div>"sv; });
108 if (i.fCurlExample) {
109 i.fCurlExample->Apply ([&] (
const String& i) { tmpCurl <<
"<div>"sv << substVars (i) <<
"</div>"sv; });
111 writeDocs (i.fOperation, tmpDocs, tmpCurl);
113 response.writeln (
"</ul>"sv);
114 response.writeln (
"</body>"sv);
115 response.writeln (
"</html>"sv);
#define Stroika_Foundation_Debug_OptionalizeTraceArgs(...)
Similar to String, but intended to more efficiently construct a String. Mutable type (String is large...
String is like std::u32string, except it is much easier to use, often much more space efficient,...
nonvirtual String ReplaceAll(const RegularExpression ®Ex, const String &with) const
A generalization of a vector: a container whose elements are keyed by the natural numbers.
Set<T> is a container of T, where once an item is added, additionally adds () do nothing.
ClientErrorException is to capture exceptions caused by a bad (e.g ill-formed) request.
Iterable<T> is a base class for containers which easily produce an Iterator<T> to traverse them.
void Throw(T &&e2Throw)
identical to builtin C++ 'throw' except that it does helpful, type dependent DbgTrace() messages firs...