proxygen
HTTPConnector.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 
20 
21 namespace proxygen {
22 
23 class HTTPUpstreamSession;
24 extern const std::string empty_string;
25 
33  public:
38  class Callback {
39  public:
40  virtual ~Callback() {}
41  virtual void connectSuccess(HTTPUpstreamSession* session) = 0;
42  virtual void connectError(
43  const folly::AsyncSocketException& ex) = 0;
44  };
45 
57  HTTPConnector(Callback* callback, folly::HHWheelTimer* timeoutSet);
58 
59  HTTPConnector(Callback* callback, const WheelTimerInstance& timeout);
60 
65  ~HTTPConnector() override;
66 
72  void reset();
73 
78  void setPlaintextProtocol(const std::string& plaintextProto);
79 
84  void setHTTPVersionOverride(bool enabled);
85 
99  void connect(
100  folly::EventBase* eventBase,
101  const folly::SocketAddress& connectAddr,
102  std::chrono::milliseconds timeoutMs = std::chrono::milliseconds(0),
103  const folly::AsyncSocket::OptionMap& socketOptions =
105  const folly::SocketAddress& bindAddr =
107 
123  void connectSSL(
124  folly::EventBase* eventBase,
125  const folly::SocketAddress& connectAddr,
126  const std::shared_ptr<folly::SSLContext>& ctx,
127  SSL_SESSION* session = nullptr,
128  std::chrono::milliseconds timeoutMs = std::chrono::milliseconds(0),
129  const folly::AsyncSocket::OptionMap& socketOptions =
131  const folly::SocketAddress& bindAddr =
133  const std::string& serverName = empty_string);
134 
139  std::chrono::milliseconds timeElapsed();
140 
145  bool isBusy() const { return socket_.get(); }
146 
147  void setHTTPCodecFactory(std::unique_ptr<DefaultHTTPCodecFactory> factory) {
148  httpCodecFactory_ = std::move(factory);
149  }
150 
151  protected:
152  void connectSuccess() noexcept override;
154  noexcept override;
155 
156 
163  std::unique_ptr<DefaultHTTPCodecFactory> httpCodecFactory_;
164 };
165 
166 }
virtual void connectSuccess(HTTPUpstreamSession *session)=0
wangle::TransportInfo transportInfo_
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
std::unique_ptr< DefaultHTTPCodecFactory > httpCodecFactory_
requires E e noexcept(noexcept(s.error(std::move(e))))
folly::AsyncTransportWrapper::UniquePtr socket_
std::map< OptionKey, int > OptionMap
Definition: AsyncSocket.h:376
void setHTTPVersionOverride(bool enabled)
std::unique_ptr< AsyncTransportWrapper, Destructor > UniquePtr
static const folly::SocketAddress & anyAddress()
WheelTimerInstance timeout_
virtual void connectError(const folly::AsyncSocketException &ex)=0
void setHTTPCodecFactory(std::unique_ptr< DefaultHTTPCodecFactory > factory)
static const OptionMap emptyOptionMap
Definition: AsyncSocket.h:378
void setPlaintextProtocol(const std::string &plaintextProto)
std::chrono::milliseconds timeElapsed()
SteadyClock::time_point TimePoint
Definition: Time.h:25
const std::string empty_string
Definition: HTTPHeaders.cpp:23
const char * string
Definition: Conv.cpp:212
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 connectSSL(folly::EventBase *eventBase, const folly::SocketAddress &connectAddr, const std::shared_ptr< folly::SSLContext > &ctx, SSL_SESSION *session=nullptr, std::chrono::milliseconds timeoutMs=std::chrono::milliseconds(0), const folly::AsyncSocket::OptionMap &socketOptions=folly::AsyncSocket::emptyOptionMap, const folly::SocketAddress &bindAddr=folly::AsyncSocket::anyAddress(), const std::string &serverName=empty_string)
void connectErr(const folly::AsyncSocketException &ex) noexceptoverride
HTTPConnector(Callback *callback, folly::HHWheelTimer *timeoutSet)
std::string plaintextProtocol_