summaryrefslogtreecommitdiff
path: root/chromium/net/third_party/quiche/src/quiche/balsa/balsa_visitor_interface.h
blob: b05d7ad05c4b7e079977ed02c62c88913ab4d829 (plain)
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
// Copyright 2021 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef QUICHE_BALSA_BALSA_VISITOR_INTERFACE_H_
#define QUICHE_BALSA_BALSA_VISITOR_INTERFACE_H_

#include <cstddef>

#include "absl/strings/string_view.h"
#include "quiche/balsa/balsa_enums.h"
#include "quiche/common/platform/api/quiche_export.h"

namespace quiche {

class BalsaHeaders;

// By default the BalsaFrame instantiates a class derived from this interface
// that does absolutely nothing. If you'd prefer to have interesting
// functionality execute when any of the below functions are called by the
// BalsaFrame, then you should subclass it, and set an instantiation of your
// subclass as the current visitor for the BalsaFrame class using
// BalsaFrame::set_visitor().
class QUICHE_EXPORT_PRIVATE BalsaVisitorInterface {
 public:
  virtual ~BalsaVisitorInterface() {}

  // Summary:
  //   This is how the BalsaFrame passes you the raw input that it knows to be a
  //   part of the body. To be clear, every byte of the Balsa that isn't part of
  //   the header (or its framing), or trailers will be passed through this
  //   function.  This includes data as well as chunking framing.
  // Arguments:
  //   input - the raw input that is part of the body.
  virtual void OnRawBodyInput(absl::string_view input) = 0;

  // Summary:
  //   This is like OnRawBodyInput, but it will only include those parts of the
  //   body that would be stored by a program such as wget, i.e. the bytes
  //   indicating chunking will have been removed. Trailers will not be passed
  //   in through this function-- they'll be passed in through OnTrailerInput.
  // Arguments:
  //   input - the part of the body.
  virtual void OnBodyChunkInput(absl::string_view input) = 0;

  // Summary:
  //   BalsaFrame passes the raw header data through this function. This is not
  //   cleaned up in any way.
  // Arguments:
  //   input - raw header data.
  virtual void OnHeaderInput(absl::string_view input) = 0;

  // Summary:
  //   BalsaFrame passes the raw trailer data through this function. This is not
  //   cleaned up in any way.  Note that trailers only occur in a message if
  //   there was a chunked encoding, and not always then.
  // Arguments:
  //   input - raw trailer data.
  virtual void OnTrailerInput(absl::string_view input) = 0;

  // Summary:
  //   Since the BalsaFrame already has to parse the headers in order to
  //   determine proper framing, it might as well pass the parsed and cleaned-up
  //   results to whatever might need it.  This function exists for that
  //   purpose-- parsed headers are passed into this function.
  // Arguments:
  //   headers - contains the parsed headers in the order in which
  //             they occurred in the header.
  virtual void ProcessHeaders(const BalsaHeaders& headers) = 0;

  // Summary:
  //   Since the BalsaFrame already has to parse the trailer, it might as well
  //   pass the parsed and cleaned-up results to whatever might need it.  This
  //   function exists for that purpose-- parsed trailer is passed into this
  //   function. This will not be called if the trailer_ object is not set in
  //   the framer, even if trailer exists in request/response.
  // Arguments:
  //   trailer - contains the parsed headers in the order in which
  //             they occurred in the trailer.
  virtual void ProcessTrailers(const BalsaHeaders& trailer) = 0;

  // Summary:
  //   Called when the first line of the message is parsed, in this case, for a
  //   request.
  // Arguments:
  //   line_input        - the first line string,
  //   method_input      - the method substring,
  //   request_uri_input - request uri substring,
  //   version_input     - the version substring.
  virtual void OnRequestFirstLineInput(absl::string_view line_input,
                                       absl::string_view method_input,
                                       absl::string_view request_uri,
                                       absl::string_view version_input) = 0;

  // Summary:
  //   Called when the first line of the message is parsed, in this case, for a
  //   response.
  // Arguments:
  //   line_input    - the first line string,
  //   version_input - the version substring,
  //   status_input  - the status substring,
  //   reason_input  - the reason substring.
  virtual void OnResponseFirstLineInput(absl::string_view line_input,
                                        absl::string_view version_input,
                                        absl::string_view status_input,
                                        absl::string_view reason_input) = 0;

  // Summary:
  //   Called when a chunk length is parsed.
  // Arguments:
  //   chunk length - the length of the next incoming chunk.
  virtual void OnChunkLength(size_t chunk_length) = 0;

  // Summary:
  //   BalsaFrame passes the raw chunk extension data through this function.
  //   The data is not cleaned up at all.
  // Arguments:
  //   input - contains the bytes available for read.
  virtual void OnChunkExtensionInput(absl::string_view input) = 0;

  // Summary:
  //   Called when the header is framed and processed.
  virtual void HeaderDone() = 0;

  // Summary:
  //   Called when the 100 Continue headers are framed and processed.
  virtual void ContinueHeaderDone() = 0;

  // Summary:
  //   Called when the message is framed and processed.
  virtual void MessageDone() = 0;

  // Summary:
  //   Called when an error is detected
  // Arguments:
  //   error_code - the error which is to be reported.
  virtual void HandleError(BalsaFrameEnums::ErrorCode error_code) = 0;

  // Summary:
  //   Called when something meriting a warning is detected
  // Arguments:
  //   error_code - the warning which is to be reported.
  virtual void HandleWarning(BalsaFrameEnums::ErrorCode error_code) = 0;
};

}  // namespace quiche

#endif  // QUICHE_BALSA_BALSA_VISITOR_INTERFACE_H_