proxygen
HTTPEvent.h
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  */
10 #pragma once
11 
12 #include <glog/logging.h>
15 
16 namespace proxygen {
17 
27 class HTTPEvent {
28  public:
29  enum class Type: uint8_t {
30  // Ingress events
33  BODY,
38  UPGRADE
39  };
40 
42  Type event, bool upgrade = false):
43  streamID_(streamID), length_(0), event_(event),
44  upgrade_(upgrade) {}
45 
47  Type event, size_t length):
48  streamID_(streamID), length_(length), event_(event),
49  upgrade_(false) {
50  // This constructor should only be used for CHUNK_HEADER.
51  // (Ideally we would take the event type as a template parameter
52  // so we could enforce this check at compile time. Unfortunately,
53  // that would prevent us from using this constructor with
54  // deferredCallbacks_.emplace().)
55  CHECK(event == Type::CHUNK_HEADER);
56  }
57 
59  Type event, std::unique_ptr<HTTPMessage> headers):
60  headers_(std::move(headers)), streamID_(streamID), length_(0),
61  event_(event), upgrade_(false) {}
62 
64  Type event, std::unique_ptr<folly::IOBuf> body):
65  body_(std::move(body)), streamID_(streamID), length_(0),
66  event_(event), upgrade_(false) {}
67 
69  Type event, std::unique_ptr<HTTPHeaders> trailers):
70  trailers_(std::move(trailers)), streamID_(streamID), length_(0),
71  event_(event), upgrade_(false) {}
72 
74  Type event, std::unique_ptr<HTTPException> error):
75  error_(std::move(error)), streamID_(streamID), length_(0),
76  event_(event), upgrade_(false) {}
77 
79  Type event, UpgradeProtocol protocol):
80  streamID_(streamID), length_(0), event_(event),
81  upgrade_(false), protocol_(protocol) {}
82 
83  Type getEvent() const { return event_; }
84 
86 
87  std::unique_ptr<HTTPMessage> getHeaders() { return std::move(headers_); }
88 
89  std::unique_ptr<folly::IOBuf> getBody() { return std::move(body_); }
90 
91  std::unique_ptr<HTTPException> getError() { return std::move(error_); }
92 
93  bool isUpgrade() const {
95  return upgrade_;
96  }
97 
98  size_t getChunkLength() const {
99  CHECK(event_ == Type::CHUNK_HEADER);
100  return length_;
101  }
102 
103  std::unique_ptr<HTTPHeaders> getTrailers() {
104  return std::move(trailers_);
105  }
106 
108  return protocol_;
109  }
110 
111  private:
112  std::unique_ptr<HTTPMessage> headers_;
113  std::unique_ptr<folly::IOBuf> body_;
114  std::unique_ptr<HTTPHeaders> trailers_;
115  std::unique_ptr<HTTPException> error_;
117  size_t length_; // Only valid when event_ == CHUNK_HEADER
119  bool upgrade_; // Only valid when event_ == MESSAGE_COMPLETE
121 };
122 
123 std::ostream& operator<<(std::ostream& os, HTTPEvent::Type e);
124 
125 }
HTTPEvent(HTTPCodec::StreamID streamID, Type event, std::unique_ptr< folly::IOBuf > body)
Definition: HTTPEvent.h:63
UpgradeProtocol getUpgradeProtocol()
Definition: HTTPEvent.h:107
HTTPEvent(HTTPCodec::StreamID streamID, Type event, UpgradeProtocol protocol)
Definition: HTTPEvent.h:78
std::ostream & operator<<(std::ostream &os, const HeaderTable &table)
std::unique_ptr< HTTPException > error_
Definition: HTTPEvent.h:115
std::unique_ptr< folly::IOBuf > getBody()
Definition: HTTPEvent.h:89
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
STL namespace.
std::unique_ptr< HTTPException > getError()
Definition: HTTPEvent.h:91
std::unique_ptr< HTTPMessage > headers_
Definition: HTTPEvent.h:112
requires And< SemiMovable< VN >... > &&SemiMovable< E > auto error(E e)
Definition: error.h:48
HTTPCodec::StreamID getStreamID() const
Definition: HTTPEvent.h:85
UpgradeProtocol protocol_
Definition: HTTPEvent.h:120
Type getEvent() const
Definition: HTTPEvent.h:83
std::unique_ptr< HTTPMessage > getHeaders()
Definition: HTTPEvent.h:87
bool isUpgrade() const
Definition: HTTPEvent.h:93
std::unique_ptr< HTTPHeaders > getTrailers()
Definition: HTTPEvent.h:103
std::unique_ptr< folly::IOBuf > body_
Definition: HTTPEvent.h:113
HTTPEvent(HTTPCodec::StreamID streamID, Type event, bool upgrade=false)
Definition: HTTPEvent.h:41
HTTPEvent(HTTPCodec::StreamID streamID, Type event, std::unique_ptr< HTTPHeaders > trailers)
Definition: HTTPEvent.h:68
HTTPEvent(HTTPCodec::StreamID streamID, Type event, std::unique_ptr< HTTPMessage > headers)
Definition: HTTPEvent.h:58
std::unique_ptr< HTTPHeaders > trailers_
Definition: HTTPEvent.h:114
HTTPCodec::StreamID streamID_
Definition: HTTPEvent.h:116
HTTPEvent(HTTPCodec::StreamID streamID, Type event, size_t length)
Definition: HTTPEvent.h:46
uint64_t StreamID
Definition: HTTPCodec.h:49
uint32_t streamID
Definition: SPDYCodec.cpp:131
size_t getChunkLength() const
Definition: HTTPEvent.h:98
HTTPEvent(HTTPCodec::StreamID streamID, Type event, std::unique_ptr< HTTPException > error)
Definition: HTTPEvent.h:73