proxygen
proxygen::HTTPRequestVerifier Class Reference

#include <HTTPRequestVerifier.h>

Public Member Functions

 HTTPRequestVerifier ()
 
void reset (HTTPMessage *msg)
 
bool setMethod (folly::StringPiece method)
 
bool setPath (folly::StringPiece path)
 
bool setScheme (folly::StringPiece scheme)
 
bool setAuthority (folly::StringPiece authority)
 
bool setUpgradeProtocol (folly::StringPiece protocol)
 
bool validate ()
 
void setMessage (HTTPMessage *msg)
 
void setHasMethod (bool hasMethod)
 
void setHasPath (bool hasPath)
 
void setHasScheme (bool hasScheme)
 
void setHasAuthority (bool hasAuthority)
 
void setHasUpgradeProtocol (bool val)
 
bool hasUpgradeProtocol ()
 

Public Attributes

std::string error
 

Private Attributes

HTTPMessagemsg_ {nullptr}
 
bool hasMethod_ {false}
 
bool hasPath_ {false}
 
bool hasScheme_ {false}
 
bool hasAuthority_ {false}
 
bool hasUpgradeProtocol_ {false}
 

Detailed Description

Definition at line 18 of file HTTPRequestVerifier.h.

Constructor & Destructor Documentation

proxygen::HTTPRequestVerifier::HTTPRequestVerifier ( )
inlineexplicit

Definition at line 20 of file HTTPRequestVerifier.h.

20 {}

Member Function Documentation

bool proxygen::HTTPRequestVerifier::hasUpgradeProtocol ( )
inline

Definition at line 150 of file HTTPRequestVerifier.h.

References hasUpgradeProtocol_.

Referenced by proxygen::HTTP2Codec::onHeadersComplete().

150  {
151  return hasUpgradeProtocol_;
152  }
void proxygen::HTTPRequestVerifier::reset ( HTTPMessage msg)
inline
bool proxygen::HTTPRequestVerifier::setAuthority ( folly::StringPiece  authority)
inline

Definition at line 81 of file HTTPRequestVerifier.h.

References proxygen::HTTPHeaders::add(), error, proxygen::HTTPMessage::getHeaders(), hasAuthority_, proxygen::HTTP_HEADER_HOST, msg_, folly::Range< Iter >::str(), proxygen::CodecUtil::STRICT, and proxygen::CodecUtil::validateHeaderValue().

Referenced by proxygen::HeaderDecodeInfo::onHeader().

81  {
82  if (hasAuthority_) {
83  error = "Duplicate authority";
84  return false;
85  }
87  error = "Invalid authority";
88  return false;
89  }
90  hasAuthority_ = true;
91  assert(msg_ != nullptr);
92  msg_->getHeaders().add(HTTP_HEADER_HOST, authority.str());
93  return true;
94  }
std::string str() const
Definition: Range.h:591
HTTPHeaders & getHeaders()
Definition: HTTPMessage.h:273
void add(folly::StringPiece name, folly::StringPiece value)
Definition: HTTPHeaders.cpp:52
static bool validateHeaderValue(folly::ByteRange value, CtlEscapeMode mode)
Definition: CodecUtil.h:66
void proxygen::HTTPRequestVerifier::setHasAuthority ( bool  hasAuthority)
inline

Definition at line 142 of file HTTPRequestVerifier.h.

References hasAuthority_.

142  {
143  hasAuthority_ = hasAuthority;
144  }
void proxygen::HTTPRequestVerifier::setHasMethod ( bool  hasMethod)
inline

Definition at line 130 of file HTTPRequestVerifier.h.

References hasMethod_.

130  {
131  hasMethod_ = hasMethod;
132  }
void proxygen::HTTPRequestVerifier::setHasPath ( bool  hasPath)
inline

Definition at line 134 of file HTTPRequestVerifier.h.

References hasPath_.

134  {
135  hasPath_ = hasPath;
136  }
void proxygen::HTTPRequestVerifier::setHasScheme ( bool  hasScheme)
inline

Definition at line 138 of file HTTPRequestVerifier.h.

References hasScheme_.

138  {
139  hasScheme_ = hasScheme;
140  }
void proxygen::HTTPRequestVerifier::setHasUpgradeProtocol ( bool  val)
inline

Definition at line 146 of file HTTPRequestVerifier.h.

References hasUpgradeProtocol_, and val.

Referenced by setUpgradeProtocol().

146  {
148  }
double val
Definition: String.cpp:273
void proxygen::HTTPRequestVerifier::setMessage ( HTTPMessage msg)
inline

Definition at line 126 of file HTTPRequestVerifier.h.

References msg_.

126  {
127  msg_ = msg;
128  }
bool proxygen::HTTPRequestVerifier::setMethod ( folly::StringPiece  method)
inline

Definition at line 32 of file HTTPRequestVerifier.h.

References error, hasMethod_, msg_, proxygen::HTTPMessage::setMethod(), and proxygen::CodecUtil::validateMethod().

Referenced by proxygen::HeaderDecodeInfo::onHeader().

32  {
33  if (hasMethod_) {
34  error = "Duplicate method";
35  return false;
36  }
37  if (!CodecUtil::validateMethod(method)) {
38  error = "Invalid method";
39  return false;
40  }
41  hasMethod_ = true;
42  assert(msg_ != nullptr);
43  msg_->setMethod(method);
44  return true;
45  }
static bool validateMethod(folly::ByteRange method)
Definition: CodecUtil.h:33
void setMethod(HTTPMethod method)
bool proxygen::HTTPRequestVerifier::setPath ( folly::StringPiece  path)
inline

Definition at line 47 of file HTTPRequestVerifier.h.

References error, hasPath_, msg_, proxygen::HTTPMessage::setURL(), folly::Range< Iter >::str(), and proxygen::CodecUtil::validateURL().

Referenced by proxygen::HeaderDecodeInfo::onHeader().

47  {
48  if (hasPath_) {
49  error = "Duplicate path";
50  return false;
51  }
52  if (!CodecUtil::validateURL(path)) {
53  error = "Invalid url";
54  return false;
55  }
56  hasPath_ = true;
57  assert(msg_ != nullptr);
58  msg_->setURL(path.str());
59  return true;
60  }
std::string str() const
Definition: Range.h:591
ParseURL setURL(T &&url)
Definition: HTTPMessage.h:183
static bool validateURL(folly::ByteRange url)
Definition: CodecUtil.h:29
bool proxygen::HTTPRequestVerifier::setScheme ( folly::StringPiece  scheme)
inline

Definition at line 62 of file HTTPRequestVerifier.h.

References error, hasScheme_, proxygen::headers::kHttps, msg_, proxygen::HTTPMessage::setSecure(), and proxygen::CodecUtil::validateMethod().

Referenced by proxygen::HeaderDecodeInfo::onHeader().

62  {
63  if (hasScheme_) {
64  error = "Duplicate scheme";
65  return false;
66  }
67  // This just checks for alpha chars
68  if (!CodecUtil::validateMethod(scheme)) {
69  error = "Invalid scheme";
70  return false;
71  }
72  hasScheme_ = true;
73  // TODO support non http/https schemes
74  if (scheme == headers::kHttps) {
75  assert(msg_ != nullptr);
76  msg_->setSecure(true);
77  }
78  return true;
79  }
static bool validateMethod(folly::ByteRange method)
Definition: CodecUtil.h:33
void setSecure(bool secure)
Definition: HTTPMessage.h:534
const std::string kHttps
bool proxygen::HTTPRequestVerifier::setUpgradeProtocol ( folly::StringPiece  protocol)
inline

Definition at line 96 of file HTTPRequestVerifier.h.

References error, hasUpgradeProtocol_, msg_, setHasUpgradeProtocol(), and proxygen::HTTPMessage::setUpgradeProtocol().

Referenced by proxygen::HeaderDecodeInfo::onHeader().

96  {
97  if (hasUpgradeProtocol_) {
98  error = "Duplicate protocol";
99  return false;
100  }
101  setHasUpgradeProtocol(true);
102  msg_->setUpgradeProtocol(folly::to<std::string>(protocol));
103  return true;
104  }
void setUpgradeProtocol(std::string protocol)
Definition: HTTPMessage.h:375
bool proxygen::HTTPRequestVerifier::validate ( )
inline

Definition at line 106 of file HTTPRequestVerifier.h.

References proxygen::CONNECT, error, proxygen::HTTPMessage::getMethod(), hasAuthority_, hasMethod_, hasPath_, hasScheme_, hasUpgradeProtocol_, and msg_.

Referenced by proxygen::HeaderDecodeInfo::onHeadersComplete().

106  {
107  if (error.size()) {
108  return false;
109  }
110  if (msg_->getMethod() == HTTPMethod::CONNECT) {
111  if ((!hasUpgradeProtocol_ &&
114  error = folly::to<std::string>("Malformed CONNECT request m/a/s/pa/pr=",
117  }
118  } else if (hasUpgradeProtocol_ || !hasMethod_ || !hasScheme_ || !hasPath_) {
119  error = folly::to<std::string>("Malformed request m/a/s/pa/pr=",
122  }
123  return error.empty();
124  }
folly::Optional< HTTPMethod > getMethod() const

Member Data Documentation

bool proxygen::HTTPRequestVerifier::hasAuthority_ {false}
private

Definition at line 161 of file HTTPRequestVerifier.h.

Referenced by reset(), setAuthority(), setHasAuthority(), and validate().

bool proxygen::HTTPRequestVerifier::hasMethod_ {false}
private

Definition at line 158 of file HTTPRequestVerifier.h.

Referenced by reset(), setHasMethod(), setMethod(), and validate().

bool proxygen::HTTPRequestVerifier::hasPath_ {false}
private

Definition at line 159 of file HTTPRequestVerifier.h.

Referenced by reset(), setHasPath(), setPath(), and validate().

bool proxygen::HTTPRequestVerifier::hasScheme_ {false}
private

Definition at line 160 of file HTTPRequestVerifier.h.

Referenced by reset(), setHasScheme(), setScheme(), and validate().

bool proxygen::HTTPRequestVerifier::hasUpgradeProtocol_ {false}
private
HTTPMessage* proxygen::HTTPRequestVerifier::msg_ {nullptr}
private

The documentation for this class was generated from the following file: