proxygen
HTTPCodecPrinter.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015-present, Facebook, Inc.
3  * All rights reserved.
4  *
5  * This source code is licensed under the BSD-style license found in the
6  * LICENSE file in the root directory of this source tree. An additional grant
7  * of patent rights can be found in the PATENTS file in the same directory.
8  *
9  */
11 
12 #include <iostream>
13 
14 namespace proxygen {
15 
17  StreamID stream_id,
18  uint8_t flags,
19  uint64_t length,
20  uint8_t type,
21  uint16_t version) {
22  switch (call_->getProtocol()) {
25  if (version > 0) {
26  // Print frame header info of SPDY control frames
27  std::cout << "[CTRL FRAME] version=" << version << ", flags="
28  << std::hex << folly::to<unsigned int>(flags) << std::dec
29  << ", length=" << length
30  << ", type=" << type
31  << std::endl;
32  } else {
33  // Print frame header info of SPDY data frames and HTTP/2 frames
34  std::cout << "[DATA FRAME] stream_id=" << stream_id << ", flags="
35  << std::hex << folly::to<unsigned int>(flags) << std::dec
36  << ", length=" << length
37  << ", type=" << type
38  << std::endl;
39  }
40  break;
42  std::cout << "[FRAME] stream_id=" << stream_id << ", flags="
43  << std::hex << folly::to<unsigned int>(flags) << std::dec
44  << ", length=" << length
45  << ", type=" << type
46  << std::endl;
47  break;
49  default:
50  break;
51  }
52  callback_->onFrameHeader(stream_id, flags, length, type, version);
53 }
54 
56  const HTTPException& error,
57  bool newStream) {
58  std::cout << "[Exception] " << error.what() << std::endl;
59  callback_->onError(stream, error, newStream);
60 }
61 
63  std::unique_ptr<folly::IOBuf> chain,
64  uint16_t padding) {
65  std::cout << "DataChunk: stream_id=" << stream
66  << ", length=" << chain->length()
67  << ", padding=" << padding << std::endl;
68  callback_->onBody(stream, std::move(chain), padding);
69 }
70 
71 void HTTPCodecPrinter::onMessageComplete(StreamID stream, bool upgrade) {
72  std::cout << "DataComplete: stream_id=" << stream << std::endl;
73  callback_->onMessageComplete(stream, upgrade);
74 }
75 
77  StreamID stream,
78  std::unique_ptr<HTTPMessage> msg) {
79  std::cout << "HEADERS: stream_id=" << stream
80  << ", numHeaders=" << msg->getHeaders().size() << std::endl;
81  if (msg->isRequest()) {
82  std::cout << "URL=" << msg->getURL() << std::endl;
83  } else {
84  std::cout << "Status=" << msg->getStatusCode() << std::endl;
85  }
86  msg->getHeaders().forEach([&] (
87  const std::string& header,
88  const std::string& val) {
89  std::cout << "\t" << header << ": " << val << std::endl;
90  });
91  callback_->onHeadersComplete(stream, std::move(msg));
92 }
93 
95  std::cout << "RST_STREAM: stream_id=" << stream << ", error="
96  << getErrorCodeString(code) << std::endl;
97  callback_->onAbort(stream, code);
98 }
99 
101  std::unique_ptr<folly::IOBuf> debugData) {
102  std::string debugInfo = (debugData) ? ", debug info=" +
103  std::string((char*)debugData->data(), debugData->length()) : "";
104  std::cout << "GOAWAY: lastGoodStream=" << lastGoodStream
105  << ", error=" << getErrorCodeString(code) << debugInfo << std::endl;
106  callback_->onGoaway(lastGoodStream, code, std::move(debugData));
107 }
108 
110  std::cout << "WINDOW_UPDATE: stream_id=" << stream
111  << ", delta_window_size=" << amount << std::endl;
112  callback_->onWindowUpdate(stream, amount);
113 }
114 
116  std::cout << "SETTINGS: num=" << settings.size() << std::endl;
117  for (const auto& setting: settings) {
118  std::cout << "\tid=" << folly::to<uint16_t>(setting.id)
119  << ", value=" << setting.value << std::endl;
120  }
121  callback_->onSettings(settings);
122 }
123 
125  std::cout << "SETTINGS_ACK" << std::endl;
126  callback_->onSettingsAck();
127 }
128 
130  printPing(unique_id);
131  callback_->onPingRequest(unique_id);
132 }
133 
135  printPing(unique_id);
136  callback_->onPingReply(unique_id);
137 }
138 
140  std::cout << "PING: unique_id=" << unique_id << std::endl;
141 }
142 
143 }
flags
Definition: http_parser.h:127
void onMessageComplete(StreamID stream, bool upgrade) override
void onWindowUpdate(StreamID stream, uint32_t amount) override
PskType type
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
double val
Definition: String.cpp:273
const uint8_t * data() const
Definition: IOBuf.h:499
void onBody(StreamID stream, std::unique_ptr< folly::IOBuf > chain, uint16_t padding) override
void onPingRequest(uint64_t uniqueID) override
static http_parser_settings settings
Definition: test.c:1529
requires And< SemiMovable< VN >... > &&SemiMovable< E > auto error(E e)
Definition: error.h:48
void printPing(uint64_t uniqueID)
void onPingReply(uint64_t uniqueID) override
ProtocolVersion version
void onSettings(const SettingsList &settings) override
void onGoaway(uint64_t lastGoodStreamID, ErrorCode code, std::unique_ptr< folly::IOBuf > debugData=nullptr) override
std::size_t length() const
Definition: IOBuf.h:533
const char * getErrorCodeString(ErrorCode error)
Definition: ErrorCode.cpp:18
void onHeadersComplete(StreamID stream, std::unique_ptr< HTTPMessage > msg) override
void onAbort(StreamID stream, ErrorCode code) override
std::vector< HTTPSetting > SettingsList
Definition: HTTPSettings.h:81
void onFrameHeader(StreamID stream_id, uint8_t flags, uint64_t length, uint8_t type, uint16_t version=0) override
const char * string
Definition: Conv.cpp:212
const char * what(void) const noexceptoverride
Definition: Exception.cpp:26
void onError(StreamID stream, const HTTPException &error, bool newStream=false) override