proxygen
CurlClient.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 #include <proxygen/lib/utils/URL.h>
17 
18 namespace CurlService {
19 
22 
23  public:
25  proxygen::HTTPMethod httpMethod,
26  const proxygen::URL& url,
27  const proxygen::URL* proxy,
28  const proxygen::HTTPHeaders& headers,
29  const std::string& inputFilename,
30  bool h2c = false,
31  unsigned short httpMajor = 1,
32  unsigned short httpMinor = 1);
33 
34  virtual ~CurlClient() = default;
35 
36  static proxygen::HTTPHeaders parseHeaders(const std::string& headersString);
37 
38  // initial SSL related structures
39  void initializeSsl(const std::string& caPath,
40  const std::string& nextProtos,
41  const std::string& certPath = "",
42  const std::string& keyPath = "");
44 
45  // HTTPConnector methods
46  void connectSuccess(proxygen::HTTPUpstreamSession* session) override;
47  void connectError(const folly::AsyncSocketException& ex) override;
48 
49  // HTTPTransactionHandler methods
50  void setTransaction(proxygen::HTTPTransaction* txn) noexcept override;
51  void detachTransaction() noexcept override;
52  void onHeadersComplete(
53  std::unique_ptr<proxygen::HTTPMessage> msg) noexcept override;
54  void onBody(std::unique_ptr<folly::IOBuf> chain) noexcept override;
55  void onTrailers(
56  std::unique_ptr<proxygen::HTTPHeaders> trailers) noexcept override;
57  void onEOM() noexcept override;
58  void onUpgrade(proxygen::UpgradeProtocol protocol) noexcept override;
59  void onError(const proxygen::HTTPException& error) noexcept override;
60  void onEgressPaused() noexcept override;
61  void onEgressResumed() noexcept override;
62 
64 
65  // Getters
67 
68  const std::string& getServerName() const;
69 
70  void setFlowControlSettings(int32_t recvWindow);
71 
73  return response_.get();
74  }
75 
76  void setLogging(bool enabled) {
77  loggingEnabled_ = enabled;
78  }
79 
80 protected:
85  std::unique_ptr<proxygen::URL> proxy_;
90  bool loggingEnabled_{true};
91  bool h2c_{false};
92  unsigned short httpMajor_;
93  unsigned short httpMinor_;
94 
95  std::unique_ptr<proxygen::HTTPMessage> response_;
96 };
97 
98 } // CurlService namespace
static proxygen::HTTPHeaders parseHeaders(const std::string &headersString)
Definition: CurlClient.cpp:48
folly::SSLContextPtr sslContext_
Definition: CurlClient.h:88
void onEgressResumed() noexceptoverride
Definition: CurlClient.cpp:235
proxygen::URL url_
Definition: CurlClient.h:84
folly::EventBase * evb_
Definition: CurlClient.h:82
const std::string inputFilename_
Definition: CurlClient.h:87
void onError(const proxygen::HTTPException &error) noexceptoverride
Definition: CurlClient.cpp:227
void detachTransaction() noexceptoverride
Definition: CurlClient.cpp:186
void setFlowControlSettings(int32_t recvWindow)
Definition: CurlClient.cpp:108
unsigned short httpMajor_
Definition: CurlClient.h:92
std::unique_ptr< proxygen::HTTPMessage > response_
Definition: CurlClient.h:95
void onEgressPaused() noexceptoverride
Definition: CurlClient.cpp:231
proxygen::HTTPMethod httpMethod_
Definition: CurlClient.h:83
void connectSuccess(proxygen::HTTPUpstreamSession *session) override
Definition: CurlClient.cpp:112
void onUpgrade(proxygen::UpgradeProtocol protocol) noexceptoverride
Definition: CurlClient.cpp:223
void onTrailers(std::unique_ptr< proxygen::HTTPHeaders > trailers) noexceptoverride
Definition: CurlClient.cpp:215
requires E e noexcept(noexcept(s.error(std::move(e))))
requires And< SemiMovable< VN >... > &&SemiMovable< E > auto error(E e)
Definition: error.h:48
void sslHandshakeFollowup(proxygen::HTTPUpstreamSession *session) noexcept
Definition: CurlClient.cpp:89
void connectError(const folly::AsyncSocketException &ex) override
Definition: CurlClient.cpp:178
void setTransaction(proxygen::HTTPTransaction *txn) noexceptoverride
Definition: CurlClient.cpp:183
std::shared_ptr< SSLContext > SSLContextPtr
Definition: SSLContext.h:628
void onBody(std::unique_ptr< folly::IOBuf > chain) noexceptoverride
Definition: CurlClient.cpp:201
proxygen::HTTPTransaction * txn_
Definition: CurlClient.h:81
void onEOM() noexceptoverride
Definition: CurlClient.cpp:219
virtual ~CurlClient()=default
void setLogging(bool enabled)
Definition: CurlClient.h:76
const std::string & getServerName() const
Definition: CurlClient.cpp:239
const char * string
Definition: Conv.cpp:212
void initializeSsl(const std::string &caPath, const std::string &nextProtos, const std::string &certPath="", const std::string &keyPath="")
Definition: CurlClient.cpp:69
const proxygen::HTTPMessage * getResponse() const
Definition: CurlClient.h:72
std::unique_ptr< proxygen::URL > proxy_
Definition: CurlClient.h:85
CurlClient(folly::EventBase *evb, proxygen::HTTPMethod httpMethod, const proxygen::URL &url, const proxygen::URL *proxy, const proxygen::HTTPHeaders &headers, const std::string &inputFilename, bool h2c=false, unsigned short httpMajor=1, unsigned short httpMinor=1)
Definition: CurlClient.cpp:23
void onHeadersComplete(std::unique_ptr< proxygen::HTTPMessage > msg) noexceptoverride
Definition: CurlClient.cpp:189
void sendRequest(proxygen::HTTPTransaction *txn)
Definition: CurlClient.cpp:123
proxygen::HTTPMessage request_
Definition: CurlClient.h:86
unsigned short httpMinor_
Definition: CurlClient.h:93
folly::SSLContextPtr getSSLContext()
Definition: CurlClient.h:66