Stroika Library 3.0d16
 
Loading...
Searching...
No Matches
Frameworks/WebServer/Request.h
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3 */
4#ifndef _Stroika_Framework_WebServer_Request_h_
5#define _Stroika_Framework_WebServer_Request_h_ 1
6
7#include "Stroika/Frameworks/StroikaPreComp.h"
8
9#include <optional>
10
12#include "Stroika/Foundation/Common/Common.h"
13#include "Stroika/Foundation/Common/Property.h"
16#include "Stroika/Foundation/IO/Network/HTTP/Request.h"
19
20/**
21 * \note Code-Status: <a href="Code-Status.md#Beta">Beta</a>
22 */
23
25
26 using namespace Stroika::Foundation;
29
30 /**
31 * \brief this represents a HTTP request object for the WebServer module
32 *
33 * \note Satisfies Concepts:
34 * o static_assert (not copyable<Request>);
35 * o static_assert (movable<Request>);
36 *
37 * TODO:
38 * @todo Probably/possibly hide the fInputStream and other public
39 * @todo Maybe associated TextStream, and maybe readline method goes here
40 * @todo http://stroika-bugs.sophists.com/browse/STK-726 - support Transfer-Encoding: chunked (as we do for response)
41 *
42 * \note \em Thread-Safety <a href="Thread-Safety.md#C++-Standard-Thread-Safety">C++-Standard-Thread-Safety</a>
43 */
45 private:
47
48 public:
49 /**
50 */
51 Request () = delete;
52 Request (const Request&) = delete;
53 Request (Request&& src);
55
56 public:
57 nonvirtual Request& operator= (const Request&) = delete;
58 nonvirtual Request& operator= (Request&&) noexcept;
59
60 public:
61 /**
62 * Quicky impl. Need to improve this significantly.
63 * Can call multiple times - but first time it blocks fetching data
64 */
65 nonvirtual Memory::BLOB GetBody ();
66
67 public:
68 /**
69 * Check the content-type of the argument (with InternetMediaTypesRegistry::IsA - so matches sub-types) and select
70 * the appropriate parser to return the body as a VariantValue.
71 *
72 * \note - this will block (calls GetBody()); and will throw if conversion problem/wrong contentType.
73 *
74 * \note Supported InternetMediaTypes for message body content type:
75 * o IsA (InternetMediaTypes::kJSON) (uses Variant::JSON::Reader to interpret the content)
76 *
77 * \note if content type is missing, an empty VariantValue will be returned.
78 *
79 * @todo support more content types - for now just supports JSON (xml, and string for plain text)
80 */
82
83 public:
84 /**
85 * \brief mostly looks at Connection: ARG header, but if not there takes into account HTTP-version specific defaults.
86 */
88
89 public:
90 /**
91 * @todo unclear if this SB const?
92 */
94
95 public:
96 /**
97 * This returns a (generally unseekable) stream of bytes.
98 * In most cases, this stream will be artificially narrowed to just the body part of the request.
99 * When a Content-Length is known, that is used to limit the stream. When a Transfer-Coding is used, that will return the apparent (decoded) bytes (NYI).
100 *
101 * \pre This may ONLY be called after the headers have been set (read) -- TODO DOCUMENT HOW THIS CAN BE CHECKED AND VERIFIED - I THINK ANSWER RESIDES IN CONNECTION OBJECT
102 */
104
105 public:
106 /**
107 * @see Characters::ToString ()
108 */
109 nonvirtual String ToString () const;
110
111 private:
113 Streams::InputStream::Ptr<byte> fBodyInputStream_;
114 optional<Memory::BLOB> fBody_;
115 };
116
117}
118
119/*
120 ********************************************************************************
121 ***************************** Implementation Details ***************************
122 ********************************************************************************
123 */
124#include "Request.inl"
125
126#endif /*_Stroika_Framework_WebServer_Request_h_*/
String is like std::u32string, except it is much easier to use, often much more space efficient,...
Definition String.h:201
Simple variant-value (case variant union) object, with (variant) basic types analogous to a value in ...
InputStream<>::Ptr is Smart pointer (with abstract Rep) class defining the interface to reading from ...
this represents a HTTP request object for the WebServer module
nonvirtual Streams::InputStream::Ptr< byte > GetInputStream()
nonvirtual Streams::InputStream::Ptr< byte > GetBodyStream()
Common::ReadOnlyProperty< bool > keepAliveRequested
mostly looks at Connection: ARG header, but if not there takes into account HTTP-version specific def...
nonvirtual DataExchange::VariantValue GetBodyVariantValue()