Line data Source code
1 : /** 2 : Copyright (c) 2024 Stappler LLC <admin@stappler.dev> 3 : 4 : Permission is hereby granted, free of charge, to any person obtaining a copy 5 : of this software and associated documentation files (the "Software"), to deal 6 : in the Software without restriction, including without limitation the rights 7 : to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 : copies of the Software, and to permit persons to whom the Software is 9 : furnished to do so, subject to the following conditions: 10 : 11 : The above copyright notice and this permission notice shall be included in 12 : all copies or substantial portions of the Software. 13 : 14 : THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 : IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 : FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 : AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 : LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 : OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 : THE SOFTWARE. 21 : **/ 22 : 23 : #ifndef EXTRA_WEBSERVER_WEBSERVER_REQUEST_SPWEBREQUESTCONFIG_H_ 24 : #define EXTRA_WEBSERVER_WEBSERVER_REQUEST_SPWEBREQUESTCONFIG_H_ 25 : 26 : #include "SPWebInfo.h" 27 : #include "SPUrl.h" 28 : #include "SPTime.h" 29 : 30 : namespace STAPPLER_VERSIONIZED stappler::web { 31 : 32 : class HostController; 33 : class Session; 34 : class InputFilter; 35 : class WebsocketHandler; 36 : class WebsocketConnection; 37 : 38 : class RequestController : public AllocBase { 39 : public: 40 : virtual ~RequestController(); 41 : 42 : RequestController(pool_t *, RequestInfo &&); 43 : 44 : virtual void bind(HostController *); 45 : 46 : virtual bool init(); 47 : virtual void finalize(); 48 : 49 55975 : pool_t *getPool() const { return _pool; } 50 : 51 15300 : HostController *getHost() const { return _host; } 52 : 53 33375 : const RequestInfo &getInfo() const { return _info; } 54 : 55 : float isAcceptable(StringView) const; 56 : 57 : virtual void startResponseTransmission() = 0; 58 : 59 : virtual size_t getBytesSent() const = 0; 60 : virtual void putc(int) = 0; 61 : virtual size_t write(const uint8_t *, size_t) = 0; 62 : virtual void flush() = 0; 63 : 64 : virtual bool isSecureConnection() const = 0; 65 : virtual bool isSecureAuthAllowed() const; 66 : 67 : virtual void setDocumentRoot(StringView) = 0; 68 : virtual void setContentType(StringView) = 0; 69 : virtual void setHandler(StringView) = 0; 70 : virtual void setContentEncoding(StringView) = 0; 71 : virtual void setStatus(Status status, StringView) = 0; 72 : 73 : virtual StringView getCookie(StringView name, bool removeFromHeadersTable = true) = 0; 74 : 75 : virtual void setFilename(StringView, bool updateStat = true, Time mtime = Time()) = 0; 76 : 77 : virtual StringView getRequestHeader(StringView) const = 0; 78 : virtual void foreachRequestHeaders(const Callback<void(StringView, StringView)> &) const = 0; 79 : 80 : virtual StringView getResponseHeader(StringView) const = 0; 81 : virtual void foreachResponseHeaders(const Callback<void(StringView, StringView)> &) const = 0; 82 : virtual void setResponseHeader(StringView, StringView) = 0; 83 : virtual void clearResponseHeaders() = 0; 84 : 85 : virtual StringView getErrorHeader(StringView) const = 0; 86 : virtual void foreachErrorHeaders(const Callback<void(StringView, StringView)> &) const = 0; 87 : virtual void setErrorHeader(StringView, StringView) = 0; 88 : virtual void clearErrorHeaders() = 0; 89 : 90 : virtual db::Adapter acquireDatabase(); 91 : 92 : virtual InputFilter *makeInputFilter(InputFilterAccept); 93 : virtual void setInputFilter(InputFilter *); 94 1950 : virtual InputFilter *getInputFilter() const { return _filter; } 95 : 96 : virtual Value getDefaultResult(); 97 : 98 0 : virtual WebsocketConnection *convertToWebsocket(WebsocketHandler *, allocator_t *, pool_t *) { return nullptr; } 99 : 100 : virtual void pushErrorMessage(Value &&); 101 : virtual void pushDebugMessage(Value &&); 102 : 103 : protected: 104 : friend class Request; 105 : 106 : pool_t *_pool = nullptr; 107 : RequestInfo _info; 108 : HostController *_host = nullptr; 109 : db::InputConfig _inputConfig; 110 : db::BackendInterface *_database = nullptr; 111 : 112 : Vector<Value> _debug; 113 : Vector<Value> _errors; 114 : 115 : RequestHandler *_handler = nullptr; 116 : db::User *_user = nullptr; 117 : int64_t _userId = 0; 118 : Session *_session = nullptr; 119 : InputFilter *_filter = nullptr; 120 : 121 : Map<StringView, CookieStorageInfo> _cookies; 122 : db::AccessRoleId _accessRole = db::AccessRoleId::Nobody; 123 : Vector<Pair<StringView, float>> _acceptList; 124 : }; 125 : 126 : } 127 : 128 : #endif /* EXTRA_WEBSERVER_WEBSERVER_REQUEST_SPWEBREQUESTCONFIG_H_ */