proxygen
HTTPUpstreamSession.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 
16 
17 namespace proxygen {
18 
19 class HTTPSessionStats;
20 class SPDYStats;
21 
22 class HTTPUpstreamSession final: public HTTPSession {
23  public:
35  const WheelTimerInstance& timeout,
39  std::unique_ptr<HTTPCodec> codec,
40  const wangle::TransportInfo& tinfo,
41  InfoCallback* infoCallback,
42  uint8_t maxVirtualPri = 0,
43  std::shared_ptr<const PriorityMapFactory> priorityMapFactory =
44  std::shared_ptr<const PriorityMapFactory>()) :
46  timeout,
47  std::move(sock),
48  localAddr,
49  peerAddr,
50  nullptr,
51  std::move(codec),
52  tinfo,
53  infoCallback),
54  maxVirtualPriorityLevel_(priorityMapFactory ? 0 : maxVirtualPri),
55  priorityMapFactory_(priorityMapFactory) {
56  if (sock_) {
57  auto asyncSocket = sock_->getUnderlyingTransport<folly::AsyncSocket>();
58  if (asyncSocket) {
59  asyncSocket->setBufferCallback(this);
60  }
61  }
63  }
64 
65  // uses folly::HHWheelTimer instance which is used on client side & thrift
67  folly::HHWheelTimer* timeout,
69  const folly::SocketAddress& localAddr,
70  const folly::SocketAddress& peerAddr,
71  std::unique_ptr<HTTPCodec> codec,
72  const wangle::TransportInfo& tinfo,
73  InfoCallback* infoCallback,
74  uint8_t maxVirtualPri = 0,
75  std::shared_ptr<const PriorityMapFactory> priorityMapFactory =
76  std::shared_ptr<const PriorityMapFactory>()) :
78  WheelTimerInstance(timeout),
79  std::move(sock),
80  localAddr,
81  peerAddr,
82  std::move(codec),
83  tinfo,
84  infoCallback,
85  maxVirtualPri,
86  priorityMapFactory) {
87  }
88 
89  using FilterIteratorFn = std::function<void(HTTPCodecFilter*)>;
90 
91  void detachTransactions();
92 
93  bool isDetachable(bool checkSocket=true) const override;
94 
95  void attachThreadLocals(folly::EventBase* eventBase,
96  folly::SSLContextPtr sslContext,
97  const WheelTimerInstance& timeout,
98  HTTPSessionStats* stats,
100  HeaderCodec::Stats* headerCodecStats,
101  HTTPSessionController* controller) override;
102 
103  void detachThreadLocals(bool detachSSLContext=false) override;
104 
105  void startNow() override;
106 
115 
119  bool isReplaySafe() const override;
120 
125  bool isReusable() const override;
126 
130  bool isClosing() const override;
131 
137  void drain() override {
139  }
140 
142  uint8_t level) override {
143  if (!priorityAdapter_) {
144  return HTTPSession::getHTTPPriority(level);
145  }
146  return priorityAdapter_->getHTTPPriority(level);
147  }
148 
149  private:
150  ~HTTPUpstreamSession() override;
151 
156  HTTPTransaction* /* txn */, HTTPMessage* /* msg */) override {}
157 
162  HTTPTransaction* txn) override;
163 
164  bool allTransactionsStarted() const override;
165 
168  const std::string& protocolString,
169  HTTPMessage& msg) override;
170 
171  void maybeAttachSSLContext(folly::SSLContextPtr sslContext) const;
172  void maybeDetachSSLContext() const;
173 
175 
176  std::shared_ptr<const PriorityMapFactory> priorityMapFactory_;
177  std::unique_ptr<PriorityAdapter> priorityAdapter_;
178 };
179 
180 } // proxygen
void detachThreadLocals(bool detachSSLContext=false) override
HTTPTransaction * newTransaction(HTTPTransaction::Handler *handler) override
HTTPUpstreamSession(folly::HHWheelTimer *timeout, folly::AsyncTransportWrapper::UniquePtr &&sock, const folly::SocketAddress &localAddr, const folly::SocketAddress &peerAddr, std::unique_ptr< HTTPCodec > codec, const wangle::TransportInfo &tinfo, InfoCallback *infoCallback, uint8_t maxVirtualPri=0, std::shared_ptr< const PriorityMapFactory > priorityMapFactory=std::shared_ptr< const PriorityMapFactory >())
HTTPCodecFilterChain codec_
std::unique_ptr< PriorityAdapter > priorityAdapter_
const SocketAddress peerAddr
Definition: TestUtils.cpp:20
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
CodecFactory codec
STL namespace.
folly::AsyncTransportWrapper::UniquePtr sock_
Definition: HTTPSession.h:697
#define nullptr
Definition: http_parser.c:41
bool isReplaySafe() const override
void handler(int, siginfo_t *, void *)
std::function< void(HTTPCodecFilter *)> FilterIteratorFn
std::unique_ptr< AsyncTransportWrapper, Destructor > UniquePtr
HTTPTransaction::Handler * getTransactionTimeoutHandler(HTTPTransaction *txn) override
void setupOnHeadersComplete(HTTPTransaction *, HTTPMessage *) override
void drain() override
std::shared_ptr< SSLContext > SSLContextPtr
Definition: SSLContext.h:628
HTTPUpstreamSession(const WheelTimerInstance &timeout, folly::AsyncTransportWrapper::UniquePtr &&sock, const folly::SocketAddress &localAddr, const folly::SocketAddress &peerAddr, std::unique_ptr< HTTPCodec > codec, const wangle::TransportInfo &tinfo, InfoCallback *infoCallback, uint8_t maxVirtualPri=0, std::shared_ptr< const PriorityMapFactory > priorityMapFactory=std::shared_ptr< const PriorityMapFactory >())
void maybeAttachSSLContext(folly::SSLContextPtr sslContext) const
std::shared_ptr< const PriorityMapFactory > priorityMapFactory_
void attachThreadLocals(folly::EventBase *eventBase, folly::SSLContextPtr sslContext, const WheelTimerInstance &timeout, HTTPSessionStats *stats, FilterIteratorFn fn, HeaderCodec::Stats *headerCodecStats, HTTPSessionController *controller) override
virtual folly::Optional< const HTTPMessage::HTTPPriority > getHTTPPriority(uint8_t) override
Definition: HTTPSession.h:339
const char * string
Definition: Conv.cpp:212
bool onNativeProtocolUpgrade(HTTPCodec::StreamID streamID, CodecProtocol protocol, const std::string &protocolString, HTTPMessage &msg) override
const SocketAddress localAddr
Definition: TestUtils.cpp:19
void setBufferCallback(BufferCallback *cb)
uint64_t StreamID
Definition: HTTPCodec.h:49
virtual folly::Optional< const HTTPMessage::HTTPPriority > getHTTPPriority(uint8_t level) override
bool allTransactionsStarted() const override
bool isDetachable(bool checkSocket=true) const override
uint32_t streamID
Definition: SPDYCodec.cpp:131
virtual TransportDirection getTransportDirection() const =0