23 using std::unique_ptr;
26 "connect timeout in milliseconds");
32 static const uint8_t READS_SHUTDOWN = 1;
33 static const uint8_t WRITES_SHUTDOWN = 2;
34 static const uint8_t CLOSED = READS_SHUTDOWN | WRITES_SHUTDOWN;
41 connector_{
this, timer},
46 VLOG(4) <<
"deleting ProxyHandler";
61 addr.setFromHostPort(url.getHost(), url.getPort());
64 .
status(503,
"Bad Gateway")
65 .
body(folly::to<string>(
"Could not parse server from URL: ",
73 LOG(INFO) <<
"Trying to connect to " <<
addr;
75 if (
request_->getMethod() == HTTPMethod::CONNECT) {
77 upstreamSock_->connect(
this, addr, FLAGS_proxy_connect_timeout);
81 {{SOL_SOCKET, SO_REUSEADDR}, 1}};
84 std::chrono::milliseconds(FLAGS_proxy_connect_timeout),
91 LOG(INFO) <<
"Forwarding " <<
92 ((body) ? body->computeChainDataLength() : 0) <<
" body bytes to server";
102 LOG(WARNING) <<
"Dropping " <<
103 ((body) ? body->computeChainDataLength() : 0) <<
" body bytes to server";
109 LOG(INFO) <<
"Forwarding client EOM to server";
112 LOG(INFO) <<
"Closing upgraded socket";
116 LOG(INFO) <<
"Dropping client EOM to server";
121 LOG(INFO) <<
"Established " << *session;
122 session_ = std::make_unique<SessionWrapper>(session);
124 LOG(INFO) <<
"Forwarding client request: " <<
request_->getURL()
134 .
status(503,
"Bad Gateway")
143 unique_ptr<HTTPMessage> msg)
noexcept {
145 LOG(INFO) <<
"Forwarding " << msg->getStatusCode() <<
" response to client";
151 LOG(INFO) <<
"Forwarding " <<
152 ((chain) ? chain->computeChainDataLength() : 0) <<
" body bytes to client";
158 LOG(INFO) <<
"Forwarding server EOM to client";
194 LOG(
ERROR) <<
"Aborting server txn: " << *
txn_;
249 *bufReturn = readSpace.first;
250 *lenReturn = readSpace.second;
virtual void resumeIngress()
void onServerEgressPaused() noexcept
void onEgressResumed() noexceptoverride
static const uint32_t kMaxReadSize
ResponseBuilder & status(uint16_t code, const std::string &message)
HTTPTransaction * newTransaction(HTTPTransaction::Handler *handler) override
EventBase * getEventBase() const
virtual void sendEOM() noexcept=0
proxygen::HTTPTransaction * txn_
ServerTransactionHandler serverHandler_
void writeErr(size_t bytesWritten, const folly::AsyncSocketException &ex) noexceptoverride
std::shared_ptr< folly::AsyncSocket > upstreamSock_
fbstring exceptionStr(const std::exception &e)
void onBody(std::unique_ptr< folly::IOBuf > body) noexceptoverride
constexpr detail::Map< Move > move
EventBase * getEventBase()
void getReadBuffer(void **bufReturn, size_t *lenReturn) override
bool upstreamEgressPaused_
std::unique_ptr< folly::IOBuf > move()
std::unique_ptr< SessionWrapper > session_
ResponseBuilder & body(std::unique_ptr< folly::IOBuf > bodyIn)
requires E e noexcept(noexcept(s.error(std::move(e))))
void onError(proxygen::ProxygenError err) noexceptoverride
void onEOM() noexceptoverride
std::unique_ptr< proxygen::HTTPMessage > request_
requires And< SemiMovable< VN >... > &&SemiMovable< E > auto error(E e)
static const uint32_t kMinReadSize
static EventBaseManager * get()
std::pair< void *, std::size_t > preallocate(std::size_t min, std::size_t newAllocationSize, std::size_t max=std::numeric_limits< std::size_t >::max())
virtual void sendAbort() noexcept=0
void onServerHeadersComplete(std::unique_ptr< proxygen::HTTPMessage > msg) noexcept
bool downstreamIngressPaused_
virtual void resumeIngress() noexcept=0
virtual void sendHeaders(HTTPMessage &msg) noexcept=0
void onServerBody(std::unique_ptr< folly::IOBuf > chain) noexcept
std::map< OptionKey, int > OptionMap
void requestComplete() noexceptoverride
proxygen::HTTPConnector connector_
void onServerEgressResumed() noexcept
void readDataAvailable(size_t len) noexceptoverride
virtual void recordRequest()
void connectSuccess() noexceptoverride
virtual void sendBody(std::unique_ptr< folly::IOBuf > body) noexcept=0
void onRequest(std::unique_ptr< proxygen::HTTPMessage > headers) noexceptoverride
virtual void sendBody(std::unique_ptr< folly::IOBuf > body)
void onServerError(const proxygen::HTTPException &error) noexcept
void connectError(const folly::AsyncSocketException &ex) override
virtual void pauseIngress()
void writeSuccess() noexceptoverride
DEFINE_int32(proxy_connect_timeout, 1000,"connect timeout in milliseconds")
void connectErr(const folly::AsyncSocketException &ex) noexceptoverride
static std::shared_ptr< AsyncSocket > newSocket(EventBase *evb)
void readEOF() noexceptoverride
void connect(folly::EventBase *eventBase, const folly::SocketAddress &connectAddr, std::chrono::milliseconds timeoutMs=std::chrono::milliseconds(0), const folly::AsyncSocket::OptionMap &socketOptions=folly::AsyncSocket::emptyOptionMap, const folly::SocketAddress &bindAddr=folly::AsyncSocket::anyAddress())
void readErr(const folly::AsyncSocketException &ex) noexceptoverride
virtual void pauseIngress() noexcept=0
void onServerEOM() noexcept
void postallocate(std::size_t n)
ResponseHandler * downstream_
void onEgressPaused() noexceptoverride
ThreadPoolListHook * addr
void detachServerTransaction() noexcept
const char * getErrorString(ProxygenError error)