xref: /aosp_15_r20/external/cronet/net/third_party/quiche/src/quiche/http2/test_tools/http2_trace_printer.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 #ifndef QUICHE_HTTP2_TEST_TOOLS_HTTP2_TRACE_PRINTER_H_
2 #define QUICHE_HTTP2_TEST_TOOLS_HTTP2_TRACE_PRINTER_H_
3 
4 #include <cstddef>
5 
6 #include "absl/strings/string_view.h"
7 #include "quiche/http2/core/http2_trace_logging.h"
8 #include "quiche/common/platform/api/quiche_export.h"
9 #include "quiche/spdy/core/http2_frame_decoder_adapter.h"
10 #include "quiche/spdy/core/spdy_no_op_visitor.h"
11 
12 namespace http2 {
13 namespace test {
14 
15 // A debugging utility that prints HTTP/2 wire bytes into logical HTTP/2 frame
16 // sequences using `Http2TraceLogger`.
17 class QUICHE_NO_EXPORT Http2TracePrinter {
18  public:
19   // Creates a printer with the given `perspective` prefixed with each log line
20   // (e.g., "CLIENT" or "SERVER"). The given `connection_id` is also included
21   // with each log line and distinguishes among multiple printed connections
22   // with the same `perspective`. If `consume_connection_preface` is true, the
23   // printer will attempt to consume and log the HTTP/2 client connection
24   // preface from the wire bytes.
25   explicit Http2TracePrinter(absl::string_view perspective,
26                              const void* connection_id = nullptr,
27                              bool consume_connection_preface = false);
28 
29   // Processes the `bytes` as HTTP/2 wire format and INFO logs the received
30   // frames. See `Http2TraceLogger` for more details on the logging format. If
31   // `consume_connection_preface` was passed as true to the constructor, then
32   // errors in processing the connection preface will be logged and subsequent
33   // calls to `ProcessInput()` will be a no-op.
34   void ProcessInput(absl::string_view bytes);
35 
36  private:
37   spdy::SpdyNoOpVisitor visitor_;
38   Http2TraceLogger logger_;
39   Http2DecoderAdapter decoder_;
40   const absl::string_view perspective_;
41   absl::string_view remaining_preface_;
42   bool preface_error_ = false;
43 };
44 
45 }  // namespace test
46 }  // namespace http2
47 
48 #endif  // QUICHE_HTTP2_TEST_TOOLS_HTTP2_TRACE_PRINTER_H_
49