MCPcopy Create free account
hub / github.com/Icinga/icinga2 / EnsureValidHeaders

Function EnsureValidHeaders

lib/remote/httpserverconnection.cpp:160–215  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

158}
159
160static inline
161bool EnsureValidHeaders(
162 boost::beast::flat_buffer& buf,
163 HttpApiRequest& request,
164 HttpApiResponse& response,
165 bool& shuttingDown,
166 boost::asio::yield_context& yc
167)
168{
169 namespace http = boost::beast::http;
170
171 if (shuttingDown)
172 return false;
173
174 bool httpError = false;
175 String errorMsg;
176
177 boost::system::error_code ec;
178
179 request.ParseHeader(buf, yc[ec]);
180
181 if (ec) {
182 if (ec == boost::asio::error::operation_aborted)
183 return false;
184
185 errorMsg = ec.message();
186 httpError = true;
187 } else {
188 switch (request.version()) {
189 case 10:
190 case 11:
191 break;
192 default:
193 errorMsg = "Unsupported HTTP version";
194 }
195 }
196
197 if (!errorMsg.IsEmpty() || httpError) {
198 response.result(http::status::bad_request);
199
200 if (!httpError && request[http::field::accept] == "application/json") {
201 HttpUtility::SendJsonError(response, nullptr, 400, "Bad Request: " + errorMsg);
202 } else {
203 response.set(http::field::content_type, "text/html");
204 response.body() << "<h1>Bad Request</h1><p><pre>" << errorMsg << "</pre></p>";
205 }
206
207 response.set(http::field::connection, "close");
208
209 response.Flush(yc);
210
211 return false;
212 }
213
214 return true;
215}
216
217static inline

Callers 1

ProcessMessagesMethod · 0.85

Calls 3

ParseHeaderMethod · 0.80
IsEmptyMethod · 0.45
FlushMethod · 0.45

Tested by

no test coverage detected