-
Notifications
You must be signed in to change notification settings - Fork 5
/
LoggingFilter.cpp
62 lines (51 loc) · 1.93 KB
/
LoggingFilter.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
//
// Created by victor on 24/10/17.
//
#include "LoggingFilter.h"
#include <proxygen/lib/utils/Logging.h>
#include <glog/logging.h>
#include <proxygen/httpserver/Filters.h>
#include <proxygen/httpserver/RequestHandler.h>
#include <proxygen/lib/http/HTTPMessage.h>
namespace restdbxx {
using proxygen::Filter;
LoggingFilter::LoggingFilter(proxygen::RequestHandler *upstream): Filter(upstream) {
}
void LoggingFilter::onRequest(std::unique_ptr<proxygen::HTTPMessage> headers) noexcept {
//proxygen::
VLOG(google::GLOG_INFO) << "Handling request for " << headers->getMethodString()
<< " " << headers->getPath();
//headers->dumpMessageToSink(VLOG(google::GLOG_INFO));
headers->atomicDumpMessage(google::GLOG_INFO);
upstream_->onRequest(std::move(headers));
}
void LoggingFilter::onBody(std::unique_ptr<folly::IOBuf> body) noexcept {
//std::string buffer_copy;
//body->copyBuffer();
folly::IOBuf value = body->cloneCoalescedAsValue();
VLOG(google::GLOG_INFO) << proxygen::IOBufPrinter::printChainInfo(&value);
VLOG(google::GLOG_INFO) << proxygen::IOBufPrinter::printHexFolly(&value);
upstream_->onBody(std::move(body));
}
void LoggingFilter::sendHeaders(proxygen::HTTPMessage &msg) noexcept {
// msg.getHeaders().forEach([](auto &k, auto &v) {
// VLOG(google::GLOG_INFO) << k << ": " << v;
// });
msg.atomicDumpMessage(google::GLOG_INFO);
downstream_->sendHeaders(msg);
}
void LoggingFilter::sendBody(std::unique_ptr<folly::IOBuf> body) noexcept {
folly::IOBuf value = body->cloneCoalescedAsValue();
VLOG(google::GLOG_INFO) << proxygen::IOBufPrinter::printHexFolly(&value);
Filter::sendBody(std::move(body));
}
void LoggingFilter::onEgressPaused() noexcept {
VLOG(google::GLOG_INFO) << "onEgressPaused";
upstream_->onEgressPaused();
}
void LoggingFilter::onEgressResumed() noexcept {
VLOG(google::GLOG_INFO) << "onEgressResumed";
upstream_->onEgressResumed();
}
LoggingFilter::~LoggingFilter() = default;
}