proxygen
ProxyHandler.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 
12 #include <folly/Memory.h>
16 #include "SessionWrapper.h"
17 
18 namespace proxygen {
19 class ResponseHandler;
20 }
21 
22 namespace ProxyService {
23 
24 class ProxyStats;
25 
31  public:
33 
34  ~ProxyHandler() override;
35 
36  void onRequest(std::unique_ptr<proxygen::HTTPMessage> headers)
37  noexcept override;
38 
39  void onBody(std::unique_ptr<folly::IOBuf> body) noexcept override;
40 
41  void onEOM() noexcept override;
42 
43  void onUpgrade(proxygen::UpgradeProtocol /*proto*/) noexcept override {}
44 
45  void requestComplete() noexcept override;
46 
47  void onError(proxygen::ProxygenError err) noexcept override;
48 
49  void onEgressPaused() noexcept override;
50 
51  void onEgressResumed() noexcept override;
52 
53  void detachServerTransaction() noexcept;
54  void onServerHeadersComplete(
55  std::unique_ptr<proxygen::HTTPMessage> msg) noexcept;
56  void onServerBody(std::unique_ptr<folly::IOBuf> chain) noexcept;
57  void onServerEOM() noexcept;
58  void onServerError(const proxygen::HTTPException& error) noexcept;
59  void onServerEgressPaused() noexcept;
60  void onServerEgressResumed() noexcept;
61 
62  private:
63 
64  void connectSuccess(proxygen::HTTPUpstreamSession* session) override;
65  void connectError(const folly::AsyncSocketException& ex) override;
66 
68  public:
70  : parent_(parent) {
71  }
72  private:
74 
75  void setTransaction(proxygen::HTTPTransaction* /*txn*/) noexcept override {
76  // no op
77  }
78  void detachTransaction() noexcept override {
79  parent_.detachServerTransaction();
80  }
82  std::unique_ptr<proxygen::HTTPMessage> msg) noexcept override {
83  parent_.onServerHeadersComplete(std::move(msg));
84  }
85 
86  void onBody(std::unique_ptr<folly::IOBuf> chain) noexcept override {
87  parent_.onServerBody(std::move(chain));
88  }
89 
90  void onTrailers(
91  std::unique_ptr<proxygen::HTTPHeaders> /*trailers*/) noexcept override {
92  // ignore for now
93  }
94  void onEOM() noexcept override {
95  parent_.onServerEOM();
96  }
97  void onUpgrade(proxygen::UpgradeProtocol /*protocol*/) noexcept override {
98  // ignore for now
99  }
100 
101  void onError(const proxygen::HTTPException& error) noexcept override {
102  parent_.onServerError(error);
103  }
104 
105  void onEgressPaused() noexcept override {
106  parent_.onServerEgressPaused();
107  }
108  void onEgressResumed() noexcept override {
109  parent_.onServerEgressResumed();
110  }
111 
112  };
113 
114  // AsyncSocket::ConnectCallback
115  void connectSuccess() noexcept override;
116  void connectErr(const folly::AsyncSocketException& ex) noexcept override;
117 
118  void getReadBuffer(void** bufReturn, size_t* lenReturn) override;
119  void readDataAvailable(size_t len) noexcept override;
120  void readEOF() noexcept override;
121  void readErr(const folly::AsyncSocketException& ex) noexcept override;
122 
123  void writeSuccess() noexcept override;
124  void writeErr(size_t bytesWritten,
125  const folly::AsyncSocketException& ex) noexcept override;
126 
127  void abortDownstream();
128  bool checkForShutdown();
129 
130  ProxyStats* const stats_{nullptr};
133  std::unique_ptr<SessionWrapper> session_;
135  bool clientTerminated_{false};
136 
137  std::unique_ptr<proxygen::HTTPMessage> request_;
138 
139  // Only for CONNECT
140  std::shared_ptr<folly::AsyncSocket> upstreamSock_;
141  uint8_t sockStatus_{0};
143  bool downstreamIngressPaused_{false};
144  bool upstreamEgressPaused_{false};
145 };
146 
147 }
void onServerEgressPaused() noexcept
void onHeadersComplete(std::unique_ptr< proxygen::HTTPMessage > msg) noexceptoverride
Definition: ProxyHandler.h:81
void onTrailers(std::unique_ptr< proxygen::HTTPHeaders >) noexceptoverride
Definition: ProxyHandler.h:90
ServerTransactionHandler serverHandler_
Definition: ProxyHandler.h:132
std::shared_ptr< folly::AsyncSocket > upstreamSock_
Definition: ProxyHandler.h:140
void onUpgrade(proxygen::UpgradeProtocol) noexceptoverride
Definition: ProxyHandler.h:97
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
std::unique_ptr< SessionWrapper > session_
Definition: ProxyHandler.h:133
requires E e noexcept(noexcept(s.error(std::move(e))))
std::unique_ptr< proxygen::HTTPMessage > request_
Definition: ProxyHandler.h:137
requires And< SemiMovable< VN >... > &&SemiMovable< E > auto error(E e)
Definition: error.h:48
void onServerHeadersComplete(std::unique_ptr< proxygen::HTTPMessage > msg) noexcept
void onServerBody(std::unique_ptr< folly::IOBuf > chain) noexcept
proxygen::HTTPConnector connector_
Definition: ProxyHandler.h:131
static Options cacheChainLength()
Definition: IOBufQueue.h:83
void onServerEgressResumed() noexcept
void onServerError(const proxygen::HTTPException &error) noexcept
void onUpgrade(proxygen::UpgradeProtocol) noexceptoverride
Definition: ProxyHandler.h:43
void setTransaction(proxygen::HTTPTransaction *) noexceptoverride
Definition: ProxyHandler.h:75
void onBody(std::unique_ptr< folly::IOBuf > chain) noexceptoverride
Definition: ProxyHandler.h:86
void onError(const proxygen::HTTPException &error) noexceptoverride
Definition: ProxyHandler.h:101
folly::Function< void()> parent
Definition: AtFork.cpp:34
void detachServerTransaction() noexcept