1 #ifndef DALI_WEB_ENGINE_REQUEST_INTERCEPTOR_H
2 #define DALI_WEB_ENGINE_REQUEST_INTERCEPTOR_H
5 * Copyright (c) 2021 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
22 #include <dali/public-api/common/intrusive-ptr.h>
23 #include <dali/public-api/object/property-map.h>
24 #include <dali/public-api/object/ref-object.h>
31 * @brief A class WebEngineRequestInterceptor for intercepting http request.
33 class WebEngineRequestInterceptor : public RefObject
39 WebEngineRequestInterceptor() = default;
44 virtual ~WebEngineRequestInterceptor() = default;
47 * @brief Returns request url.
49 * @return url if succeeded or empty otherwise
51 virtual std::string GetUrl() const = 0;
54 * @brief Returns http headers.
56 * @return headers if succeeded or empty otherwise
58 virtual Dali::Property::Map GetHeaders() const = 0;
61 * @brief Returns http method.
63 * @return method if succeeded or empty otherwise
65 virtual std::string GetMethod() const = 0;
68 * @brief Ignores request.
69 * @note After this call, any further calls result in undefined behavior.
70 * This function can be called only INSIDE Dali::WebEngineContext::WebEngineRequestInterceptedCallback.
72 * @return true if succeeded or false otherwise
74 virtual bool Ignore() = 0;
77 * @brief Sets status code and status text of response for intercepted request.
79 * @param[in] statusCode Status code of response
80 * @param[in] customStatusText Status code of response
82 * @return true if succeeded or false otherwise
84 virtual bool SetResponseStatus(int statusCode, const std::string& customStatusText) = 0;
87 * @brief Adds HTTP header to response for intercepted request.
89 * @param[in] fieldName Key of response header
90 * @param[in] fieldValue Value of response header
92 * @return true if succeeded or false otherwise
94 virtual bool AddResponseHeader(const std::string& fieldName, const std::string& fieldValue) = 0;
97 * @brief Adds HTTP headers to response.
99 * @param[in] headers Headers of response
101 * @return true if succeeded or false otherwise
103 virtual bool AddResponseHeaders(const Dali::Property::Map& headers) = 0;
106 * @brief Writes whole response body at once.
108 * @param[in] body Contents of response
109 * @param[in] length Length of contents of response
111 * @return true if succeeded or false otherwise
113 virtual bool AddResponseBody(const std::string& body, uint32_t length) = 0;
116 * @brief Writes whole response at once.
118 * @param[in] headers Headers of response
119 * @param[in] body Contents of response
120 * @param[in] length Length of contents of response
122 * @return true if succeeded or false otherwise
124 virtual bool AddResponse(const std::string& headers, const std::string& body, uint32_t length) = 0;
127 * @brief Writes a part of response body.
128 * @note If this function returns false, handling the request is done.
129 * Any further calls result in undefined behavior.
130 * User should always check return value, because response to this request might not be needed any more,
131 * and function can return false even though user still has data to write.
132 * This function can be called only OUTSIDE Dali::WebEngineContext::WebEngineRequestInterceptedCallback.
134 * @param[in] chunk Chunks of response
135 * @param[in] length Length of chunks of response
137 * @return true if succeeded or false otherwise
139 virtual bool WriteResponseChunk(const std::string& chunk, uint32_t length) = 0;
142 using WebEngineRequestInterceptorPtr = Dali::IntrusivePtr<WebEngineRequestInterceptor>;
146 #endif // DALI_WEB_ENGINE_REQUEST_INTERCEPTOR_H