proxygen
RequestHandlerAdaptor.cpp
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  */
11 
12 #include <boost/algorithm/string.hpp>
17 
18 namespace proxygen {
19 
21  : ResponseHandler(requestHandler) {
22 }
23 
25  txn_ = txn;
26 
27  // We become that transparent layer
29 }
30 
32  if (err_ == kErrorNone) {
34  }
35 
36  // Otherwise we would have got some error call back and invoked onError
37  // on RequestHandler
38  delete this;
39 }
40 
41 void RequestHandlerAdaptor::onHeadersComplete(std::unique_ptr<HTTPMessage> msg)
42  noexcept {
43  if (msg->getHeaders().exists(HTTP_HEADER_EXPECT) &&
45  auto expectation = msg->getHeaders().getSingleOrEmpty(HTTP_HEADER_EXPECT);
46  if (!boost::iequals(expectation, "100-continue")) {
48 
49  ResponseBuilder(this)
50  .status(417, "Expectation Failed")
52  .sendWithEOM();
53  } else {
54  ResponseBuilder(this)
55  .status(100, "Continue")
56  .send();
57 
58  }
59  }
60 
61  // Only in case of no error
62  if (err_ == kErrorNone) {
64  }
65 }
66 
67 void RequestHandlerAdaptor::onBody(std::unique_ptr<folly::IOBuf> c) noexcept {
69 }
70 
72 
74 }
75 
77  std::unique_ptr<HTTPHeaders> /*trailers*/) noexcept {
78  // XXX: Support trailers
79 }
80 
82  if (err_ == kErrorNone) {
83  upstream_->onEOM();
84  }
85 }
86 
88  upstream_->onUpgrade(protocol);
89 }
90 
92  if (err_ != kErrorNone) {
93  // we have already handled an error and upstream would have been deleted
94  return;
95  }
96 
97  if (error.getProxygenError() == kErrorTimeout) {
99 
100  if (!txn_->canSendHeaders()) {
101  sendAbort();
102  } else {
103  ResponseBuilder(this)
104  .status(408, "Request Timeout")
105  .closeConnection()
106  .sendWithEOM();
107  }
108  } else if (error.getDirection() == HTTPException::Direction::INGRESS) {
110 
111  if (!txn_->canSendHeaders()) {
112  sendAbort();
113  } else {
114  ResponseBuilder(this)
115  .status(400, "Bad Request")
116  .closeConnection()
117  .sendWithEOM();
118  }
119 
120  } else {
122  }
123 
124  // Wait for detachTransaction to clean up
125 }
126 
129 }
130 
133 }
134 
136  // Create handler for child EX transaction.
138  txn->setHandler(handler);
139 }
140 
142  txn_->sendHeaders(msg);
143 }
144 
146  txn_->sendChunkHeader(len);
147 }
148 
149 void RequestHandlerAdaptor::sendBody(std::unique_ptr<folly::IOBuf> b) noexcept {
151 }
152 
155 }
156 
158  txn_->sendEOM();
159 }
160 
162  txn_->sendAbort();
163 }
164 
166  txn_->refreshTimeout();
167 }
168 
170  txn_->pauseIngress();
171 }
172 
174  txn_->resumeIngress();
175 }
176 
178  PushHandler* pushHandler) noexcept {
179  auto pushTxn = txn_->newPushedTransaction(pushHandler->getHandler());
180  if (!pushTxn) {
181  // Codec doesn't support push
182  return nullptr;
183  }
184  auto pushHandlerAdaptor = new RequestHandlerAdaptor(pushHandler);
185  pushHandlerAdaptor->setTransaction(pushTxn);
186  return pushHandlerAdaptor;
187 }
188 
190  ExMessageHandler* exHandler,
191  bool unidirectional) noexcept {
193  getTransaction()->newExTransaction(handler, unidirectional);
194  return handler;
195 }
196 
199  return txn_->getSetupTransportInfo();
200 }
201 
203  wangle::TransportInfo* tinfo) const {
205 }
206 
208  err_ = err;
209  upstream_->onError(err);
210 }
211 
212 }
void onTrailers(std::unique_ptr< HTTPHeaders > trailers) noexceptoverride
void setTransaction(HTTPTransaction *txn) noexceptoverride
ResponseBuilder & status(uint16_t code, const std::string &message)
RequestHandlerAdaptor(RequestHandler *requestHandler)
virtual ExMessageHandler * getExHandler() noexcept
virtual void setResponseHandler(ResponseHandler *handler) noexcept
char b
virtual void onEOM() noexcept=0
void onError(const HTTPException &error) noexceptoverride
void detachTransaction() noexceptoverride
void sendHeaders(HTTPMessage &msg) noexceptoverride
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
const wangle::TransportInfo & getSetupTransportInfo() const noexcept
HTTPTransaction * getTransaction() const noexcept
virtual bool canHandleExpect() noexcept
void sendChunkTerminator() noexceptoverride
ResponseHandler * newPushedResponse(PushHandler *pushHandler) noexceptoverride
const wangle::TransportInfo & getSetupTransportInfo() const noexceptoverride
ResponseHandler * newExMessage(ExMessageHandler *exHandler, bool unidirectional) noexceptoverride
virtual void requestComplete() noexcept=0
HTTPTransaction * txn_
requires E e noexcept(noexcept(s.error(std::move(e))))
void onHeadersComplete(std::unique_ptr< HTTPMessage > msg) noexceptoverride
requires And< SemiMovable< VN >... > &&SemiMovable< E > auto error(E e)
Definition: error.h:48
void getCurrentTransportInfo(wangle::TransportInfo *tinfo) const
void handler(int, siginfo_t *, void *)
void onChunkHeader(size_t length) noexceptoverride
virtual void onEgressPaused() noexcept
void onExTransaction(HTTPTransaction *txn) noexceptoverride
virtual HTTPTransaction * newExTransaction(HTTPTransactionHandler *handler, bool unidirectional=false)
virtual void onRequest(std::unique_ptr< HTTPMessage > headers) noexcept=0
virtual void sendBody(std::unique_ptr< folly::IOBuf > body)
virtual void sendHeaders(const HTTPMessage &headers)
virtual bool canSendHeaders() const
void onUpgrade(UpgradeProtocol protocol) noexceptoverride
virtual HTTPTransaction * newPushedTransaction(HTTPPushTransactionHandler *handler)
void sendBody(std::unique_ptr< folly::IOBuf > body) noexceptoverride
void getCurrentTransportInfo(wangle::TransportInfo *tinfo) const override
void onBody(std::unique_ptr< folly::IOBuf > chain) noexceptoverride
ResponseBuilder & closeConnection()
RequestHandler * upstream_
const
Definition: upload.py:398
virtual void sendChunkTerminator()
void setError(ProxygenError err) noexcept
virtual void onUpgrade(proxygen::UpgradeProtocol prot) noexcept=0
virtual void onError(ProxygenError err) noexcept=0
char c
virtual void onEgressResumed() noexcept
void onChunkComplete() noexceptoverride
virtual void onBody(std::unique_ptr< folly::IOBuf > body) noexcept=0
void sendChunkHeader(size_t len) noexceptoverride
virtual void sendChunkHeader(size_t length)