|
19 | 19 | #include <bitcoin/network/channels/channel_http.hpp> |
20 | 20 |
|
21 | 21 | #include <bitcoin/network/async/async.hpp> |
| 22 | +#include <bitcoin/network/channels/channel.hpp> |
22 | 23 | #include <bitcoin/network/define.hpp> |
23 | 24 | #include <bitcoin/network/log/log.hpp> |
24 | | -#include <bitcoin/network/channels/channel.hpp> |
| 25 | +#include <bitcoin/network/messages/http/http.hpp> |
25 | 26 | #include <bitcoin/network/settings.hpp> |
26 | 27 |
|
27 | 28 | namespace libbitcoin { |
@@ -107,9 +108,44 @@ void channel_http::handle_read_request(const code& ec, size_t, |
107 | 108 | return; |
108 | 109 | } |
109 | 110 |
|
| 111 | + log_message(*request); |
110 | 112 | distributor_.notify(request); |
111 | 113 | } |
112 | 114 |
|
| 115 | +// log helpers |
| 116 | +// ---------------------------------------------------------------------------- |
| 117 | + |
| 118 | +void channel_http::log_message(const http::request& request) const NOEXCEPT |
| 119 | +{ |
| 120 | + LOG_ONLY(const auto size = serialize(request.payload_size() |
| 121 | + .has_value() ? request.payload_size().value() : zero);) |
| 122 | + |
| 123 | + LOG_ONLY(const auto version = "http/" + serialize(request.version() / 10) + |
| 124 | + "." + serialize(request.version() % 10);) |
| 125 | + |
| 126 | + LOGP("Request [" << request.method_string() |
| 127 | + << "] " << version << " (" << (request.chunked() ? "c" : size) |
| 128 | + << ") " << (request.keep_alive() ? "keep" : "drop") |
| 129 | + << " [" << authority() << "]" |
| 130 | + << " {" << (split(request[http::field::accept], ",").front()) << "...}" |
| 131 | + << " " << request.target()); |
| 132 | +} |
| 133 | + |
| 134 | +void channel_http::log_message(const http::response& response) const NOEXCEPT |
| 135 | +{ |
| 136 | + LOG_ONLY(const auto size = serialize(response.payload_size() |
| 137 | + .has_value() ? response.payload_size().value() : zero);) |
| 138 | + |
| 139 | + LOG_ONLY(const auto version = "http/" + serialize(response.version() / 10) |
| 140 | + + "." + serialize(response.version() % 10);) |
| 141 | + |
| 142 | + LOGP("Response [" << http::status_string(response.result()) |
| 143 | + << "] " << version << " (" << (response.chunked() ? "c" : size) |
| 144 | + << ") " << (response.keep_alive() ? "keep" : "drop") |
| 145 | + << " [" << authority() << "]" |
| 146 | + << " {" << (response[http::field::content_type]) << "}"); |
| 147 | +} |
| 148 | + |
113 | 149 | BC_POP_WARNING() |
114 | 150 | BC_POP_WARNING() |
115 | 151 | BC_POP_WARNING() |
|
0 commit comments