proxygen
HTTPException.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 <folly/Memory.h>
13 #include <folly/io/IOBufQueue.h>
17 
18 namespace proxygen {
19 
27  public:
36  enum class Direction {
37  INGRESS = 0,
38  EGRESS,
40  };
41 
42  explicit HTTPException(Direction dir, const std::string& msg)
43  : Exception(msg),
44  dir_(dir) {}
45 
47  Exception(static_cast<const Exception&>(ex)),
48  dir_(ex.dir_),
51  errno_(ex.errno_) {
52  if (ex.currentIngressBuf_) {
54  }
55  if (ex.partialMsg_) {
56  partialMsg_ = std::make_unique<HTTPMessage>(*ex.partialMsg_.get());
57  }
58  }
59 
65  std::string describe() const;
66 
68  return dir_;
69  }
70 
71  bool isIngressException() const {
72  return dir_ == Direction::INGRESS ||
74  }
75 
76  bool isEgressException() const {
77  return dir_ == Direction::EGRESS ||
79  }
80 
81  // Accessors for HTTP error codes
82  bool hasHttpStatusCode() const {
83  return (httpStatusCode_ != 0);
84  }
85 
88  }
89 
91  return httpStatusCode_;
92  }
93 
94  // Accessors for Codec specific status codes
95  bool hasCodecStatusCode() const {
96  return codecStatusCode_.hasValue();
97  }
100  }
102  CHECK(hasCodecStatusCode());
103  return *codecStatusCode_;
104  }
105 
106  // Accessors for errno
107  bool hasErrno() const {
108  return (errno_ != 0);
109  }
110  void setErrno(uint32_t e) {
111  errno_ = e;
112  }
113  uint32_t getErrno() const {
114  return errno_;
115  }
116 
117  void setCurrentIngressBuf(std::unique_ptr<folly::IOBuf> buf) {
119  }
120 
121  std::unique_ptr<folly::IOBuf> moveCurrentIngressBuf() {
123  }
124 
125  void setPartialMsg(std::unique_ptr<HTTPMessage> partialMsg) {
126  partialMsg_ = std::move(partialMsg);
127  }
128 
129  std::unique_ptr<HTTPMessage> movePartialMsg() {
130  return std::move(partialMsg_);
131  }
132 
133  private:
134 
139  // current ingress buffer, may be compressed
140  std::unique_ptr<folly::IOBuf> currentIngressBuf_;
141  // partial message that is being parsed
142  std::unique_ptr<HTTPMessage> partialMsg_;
143 };
144 
145 std::ostream& operator<<(std::ostream& os, const HTTPException& ex);
146 
147 }
HTTPException(const HTTPException &ex)
Definition: HTTPException.h:46
void setHttpStatusCode(uint32_t statusCode)
Definition: HTTPException.h:86
spdy::GoawayStatusCode statusCode
Definition: SPDYCodec.cpp:110
void setCurrentIngressBuf(std::unique_ptr< folly::IOBuf > buf)
std::unique_ptr< folly::IOBuf > moveCurrentIngressBuf()
std::ostream & operator<<(std::ostream &os, const HeaderTable &table)
bool hasCodecStatusCode() const
Definition: HTTPException.h:95
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
void setPartialMsg(std::unique_ptr< HTTPMessage > partialMsg)
bool hasHttpStatusCode() const
Definition: HTTPException.h:82
std::unique_ptr< HTTPMessage > partialMsg_
void setCodecStatusCode(ErrorCode statusCode)
Definition: HTTPException.h:98
HTTPException(Direction dir, const std::string &msg)
Definition: HTTPException.h:42
uint32_t getErrno() const
bool isIngressException() const
Definition: HTTPException.h:71
Direction getDirection() const
Definition: HTTPException.h:67
ErrorCode getCodecStatusCode() const
FOLLY_CPP14_CONSTEXPR bool hasValue() const noexcept
Definition: Optional.h:300
folly::Optional< ErrorCode > codecStatusCode_
void setErrno(uint32_t e)
bool isEgressException() const
Definition: HTTPException.h:76
const char * string
Definition: Conv.cpp:212
const
Definition: upload.py:398
std::unique_ptr< folly::IOBuf > currentIngressBuf_
std::unique_ptr< HTTPMessage > movePartialMsg()
uint32_t getHttpStatusCode() const
Definition: HTTPException.h:90
std::string describe() const