proxygen
proxygen::HTTPHandlerBase Class Reference

#include <HTTPSessionMocks.h>

Inheritance diagram for proxygen::HTTPHandlerBase:
proxygen::MockHTTPHandler proxygen::MockHTTPPushHandler

Public Types

using HeaderMap = std::map< std::string, std::string >
 

Public Member Functions

 HTTPHandlerBase ()
 
 HTTPHandlerBase (HTTPTransaction *txn, HTTPMessage *msg)
 
void terminate ()
 
void sendRequest ()
 
void sendRequest (HTTPMessage req)
 
void sendHeaders (uint32_t code, uint32_t content_length, bool keepalive=true, HeaderMap headers=HeaderMap())
 
void sendReply ()
 
void sendReplyCode (uint32_t code)
 
void sendBody (uint32_t content_length)
 
void sendBodyWithLastByteTracking (uint32_t content_length)
 
void sendReplyWithBody (uint32_t code, uint32_t content_length, bool keepalive=true, bool sendEOM=true, bool hasTrailers=false)
 
void sendEOM ()
 
void sendChunkedReplyWithBody (uint32_t code, uint32_t content_length, uint32_t chunkSize, bool hasTrailers, bool sendEOM=true)
 

Public Attributes

HTTPTransactiontxn_ {nullptr}
 
std::shared_ptr< HTTPMessagemsg_
 

Detailed Description

Definition at line 25 of file HTTPSessionMocks.h.

Member Typedef Documentation

Constructor & Destructor Documentation

proxygen::HTTPHandlerBase::HTTPHandlerBase ( )
inline

Definition at line 27 of file HTTPSessionMocks.h.

27  {
28  }
proxygen::HTTPHandlerBase::HTTPHandlerBase ( HTTPTransaction txn,
HTTPMessage msg 
)
inline

Definition at line 29 of file HTTPSessionMocks.h.

30  : txn_(txn), msg_(msg) {
31  }
std::shared_ptr< HTTPMessage > msg_

Member Function Documentation

void proxygen::HTTPHandlerBase::sendBody ( uint32_t  content_length)
inline

Definition at line 73 of file HTTPSessionMocks.h.

References folly::IOBuf::copyBuffer(), min, proxygen::HTTPTransaction::sendBody(), txn_, and uint32_t.

Referenced by sendBodyWithLastByteTracking(), sendReplyWithBody(), and TEST_F().

73  {
74  while (content_length > 0) {
75  uint32_t toSend = std::min(content_length, uint32_t(4096));
76  char buf[toSend];
77  memset(buf, 'a', toSend);
78  txn_->sendBody(folly::IOBuf::copyBuffer(buf, toSend));
79  content_length -= toSend;
80  }
81  }
LogLevel min
Definition: LogLevel.cpp:30
virtual void sendBody(std::unique_ptr< folly::IOBuf > body)
static std::unique_ptr< IOBuf > copyBuffer(const void *buf, std::size_t size, std::size_t headroom=0, std::size_t minTailroom=0)
Definition: IOBuf.h:1587
void proxygen::HTTPHandlerBase::sendBodyWithLastByteTracking ( uint32_t  content_length)
inline

Definition at line 83 of file HTTPSessionMocks.h.

References sendBody(), proxygen::HTTPTransaction::setLastByteFlushedTrackingEnabled(), and txn_.

83  {
85  sendBody(content_length);
86  }
void setLastByteFlushedTrackingEnabled(bool enabled)
void sendBody(uint32_t content_length)
void proxygen::HTTPHandlerBase::sendChunkedReplyWithBody ( uint32_t  code,
uint32_t  content_length,
uint32_t  chunkSize,
bool  hasTrailers,
bool  sendEOM = true 
)
inline

Definition at line 109 of file HTTPSessionMocks.h.

References proxygen::HTTPHeaders::add(), folly::IOBuf::copyBuffer(), min, proxygen::HTTPTransaction::sendBody(), proxygen::HTTPTransaction::sendChunkHeader(), proxygen::HTTPTransaction::sendChunkTerminator(), sendEOM(), proxygen::HTTPTransaction::sendEOM(), proxygen::HTTPTransaction::sendHeaders(), proxygen::HTTPTransaction::sendTrailers(), proxygen::HTTPMessage::setHTTPVersion(), proxygen::HTTPMessage::setIsChunked(), proxygen::HTTPMessage::setStatusCode(), txn_, and uint32_t.

113  {
114  HTTPMessage reply;
115  reply.setStatusCode(code);
116  reply.setHTTPVersion(1, 1);
117  reply.setIsChunked(true);
118  txn_->sendHeaders(reply);
119  while (content_length > 0) {
120  uint32_t toSend = std::min(content_length, chunkSize);
121  char buf[toSend];
122  memset(buf, 'a', toSend);
123  txn_->sendChunkHeader(toSend);
124  txn_->sendBody(folly::IOBuf::copyBuffer(buf, toSend));
126  content_length -= toSend;
127  }
128  if (hasTrailers) {
129  HTTPHeaders trailers;
130  trailers.add("X-Trailer1", "Foo");
131  txn_->sendTrailers(trailers);
132  }
133  if (sendEOM) {
134  txn_->sendEOM();
135  }
136  }
virtual void sendTrailers(const HTTPHeaders &trailers)
LogLevel min
Definition: LogLevel.cpp:30
virtual void sendBody(std::unique_ptr< folly::IOBuf > body)
virtual void sendHeaders(const HTTPMessage &headers)
virtual void sendChunkTerminator()
static std::unique_ptr< IOBuf > copyBuffer(const void *buf, std::size_t size, std::size_t headroom=0, std::size_t minTailroom=0)
Definition: IOBuf.h:1587
virtual void sendChunkHeader(size_t length)
void proxygen::HTTPHandlerBase::sendEOM ( )
inline

Definition at line 105 of file HTTPSessionMocks.h.

References proxygen::HTTPTransaction::sendEOM(), and txn_.

Referenced by sendChunkedReplyWithBody(), and sendReplyWithBody().

105  {
106  txn_->sendEOM();
107  }
void proxygen::HTTPHandlerBase::sendHeaders ( uint32_t  code,
uint32_t  content_length,
bool  keepalive = true,
HeaderMap  headers = HeaderMap() 
)
inline

Definition at line 48 of file HTTPSessionMocks.h.

References proxygen::HTTPHeaders::add(), proxygen::HTTPMessage::getHeaders(), proxygen::HTTP_HEADER_CONTENT_LENGTH, proxygen::HTTPTransaction::sendHeaders(), proxygen::HTTPMessage::setHTTPVersion(), proxygen::HTTPMessage::setStatusCode(), proxygen::HTTPMessage::setWantsKeepalive(), and txn_.

Referenced by sendReplyCode(), sendReplyWithBody(), and TEST_F().

51  {
52  HTTPMessage reply;
53  reply.setStatusCode(code);
54  reply.setHTTPVersion(1, 1);
55  reply.setWantsKeepalive(keepalive);
56  reply.getHeaders().add(HTTP_HEADER_CONTENT_LENGTH,
57  folly::to<std::string>(content_length));
58  for (auto& nv : headers) {
59  reply.getHeaders().add(nv.first, nv.second);
60  }
61  txn_->sendHeaders(reply);
62  }
virtual void sendHeaders(const HTTPMessage &headers)
void proxygen::HTTPHandlerBase::sendReply ( )
inline

Definition at line 64 of file HTTPSessionMocks.h.

References sendReplyCode().

64  {
65  sendReplyCode(200);
66  }
void sendReplyCode(uint32_t code)
void proxygen::HTTPHandlerBase::sendReplyCode ( uint32_t  code)
inline

Definition at line 68 of file HTTPSessionMocks.h.

References proxygen::HTTPTransaction::sendEOM(), sendHeaders(), and txn_.

Referenced by sendReply().

68  {
69  sendHeaders(code, 0, true);
70  txn_->sendEOM();
71  }
void sendHeaders(uint32_t code, uint32_t content_length, bool keepalive=true, HeaderMap headers=HeaderMap())
void proxygen::HTTPHandlerBase::sendReplyWithBody ( uint32_t  code,
uint32_t  content_length,
bool  keepalive = true,
bool  sendEOM = true,
bool  hasTrailers = false 
)
inline

Definition at line 88 of file HTTPSessionMocks.h.

References proxygen::HTTPHeaders::add(), sendBody(), sendEOM(), proxygen::HTTPTransaction::sendEOM(), sendHeaders(), proxygen::HTTPTransaction::sendTrailers(), and txn_.

Referenced by TEST_F().

92  {
93  sendHeaders(code, content_length, keepalive);
94  sendBody(content_length);
95  if (hasTrailers) {
96  HTTPHeaders trailers;
97  trailers.add("X-Trailer1", "Foo");
98  txn_->sendTrailers(trailers);
99  }
100  if (sendEOM) {
101  txn_->sendEOM();
102  }
103  }
virtual void sendTrailers(const HTTPHeaders &trailers)
void sendHeaders(uint32_t code, uint32_t content_length, bool keepalive=true, HeaderMap headers=HeaderMap())
void sendBody(uint32_t content_length)
void proxygen::HTTPHandlerBase::sendRequest ( )
inline

Definition at line 37 of file HTTPSessionMocks.h.

References proxygen::getGetRequest().

Referenced by TEST_F().

37  {
39  }
HTTPMessage getGetRequest(const std::string &url)
Definition: TestUtils.cpp:76
void proxygen::HTTPHandlerBase::sendRequest ( HTTPMessage  req)
inline

Definition at line 41 of file HTTPSessionMocks.h.

References proxygen::HTTPTransaction::sendEOM(), proxygen::HTTPTransaction::sendHeaders(), and txn_.

41  {
42  // this copies but it's test code meh
43  txn_->sendHeaders(req);
44  txn_->sendEOM();
45  }
virtual void sendHeaders(const HTTPMessage &headers)
void proxygen::HTTPHandlerBase::terminate ( )
inline

Member Data Documentation

std::shared_ptr<HTTPMessage> proxygen::HTTPHandlerBase::msg_

Definition at line 139 of file HTTPSessionMocks.h.


The documentation for this class was generated from the following file: