SNode.C
Loading...
Searching...
No Matches
VerboseRequest.cpp
Go to the documentation of this file.
1/*
2 * snode.c - a slim toolkit for network communication
3 * Copyright (C) Volker Christian <me@vchrist.at>
4 * 2020, 2021, 2022, 2023, 2024, 2025
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published
8 * by the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include "express/middleware/VerboseRequest.h"
21
22#include "core/socket/stream/SocketConnection.h"
23#include "web/http/server/SocketContext.h"
24
25#ifndef DOXYGEN_SHOULD_SKIP_THIS
26
27#include "log/Logger.h"
28#include "web/http/http_utils.h"
29
30#include <string>
31
32#endif // DOXYGEN_SHOULD_SKIP_THIS
33
34namespace express::middleware {
35
37 use([details] MIDDLEWARE(req, res, next) {
38 LOG(DEBUG) << res->getSocketContext()->getSocketConnection()->getConnectionName()
39 << " Express VerboseMiddleware: " << req->method << " " << req->url << " " << req->httpVersion << "\n"
40 << httputils::toString(
41 req->method,
42 req->url,
43 req->httpVersion,
44 (details & Details::W_QUERIES) == Details::W_QUERIES ? req->queries : web::http::CiStringMap<std::string>(),
45 (details & Details::W_HEADERS) == Details::W_HEADERS ? req->headers : web::http::CiStringMap<std::string>(),
46 (details & Details::W_COOKIES) == Details::W_COOKIES ? req->cookies : web::http::CiStringMap<std::string>(),
47 (details & Details::W_CONTENT) == Details::W_CONTENT ? req->body : std::vector<char>());
48
49 next();
50 });
51 }
52
53 class VerboseRequest& VerboseRequest(VerboseRequest::Details details) {
54 static std::shared_ptr<class VerboseRequest> verboseRequest = nullptr;
55
56 if (verboseRequest == nullptr) {
57 verboseRequest = std::shared_ptr<class VerboseRequest>(new class VerboseRequest(details));
58 }
59
60 return *verboseRequest;
61 }
62
63} // namespace express::middleware
#define MIDDLEWARE(req, res, next)
Definition Router.h:40