proxygen
MockHTTPCodec.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 
14 
15 namespace proxygen {
16 
17 #if defined(__clang__) && __clang_major__ >= 3 && __clang_minor__ >= 6
18 #pragma clang diagnostic push
19 #pragma clang diagnostic ignored "-Winconsistent-missing-override"
20 #endif
21 
22 class MockHTTPCodec: public HTTPCodec {
23  public:
31  MOCK_CONST_METHOD0(isBusy, bool());
32  MOCK_CONST_METHOD0(hasPartialTransaction, bool());
33  MOCK_METHOD1(setParserPaused, void(bool));
34  MOCK_METHOD1(onIngress, size_t(const folly::IOBuf&));
35  MOCK_METHOD0(onIngressEOF, void());
43  const HTTPMessage&,
44  bool eom,
45  HTTPHeaderSize*));
48  const HTTPMessage&,
50  bool eom,
51  HTTPHeaderSize*));
54  std::shared_ptr<folly::IOBuf>,
56  bool));
59  std::unique_ptr<folly::IOBuf> chain,
61  bool eom) override {
62  return generateBody(writeBuf,
63  stream,
64  std::shared_ptr<folly::IOBuf>(chain.release()),
65  padding,
66  eom);
67  }
70  size_t));
75  const HTTPHeaders&));
80  ErrorCode));
82  StreamID,
83  ErrorCode,
84  std::shared_ptr<folly::IOBuf>));
86  StreamID lastStream,
88  std::unique_ptr<folly::IOBuf> debugData) override {
89  return generateGoaway(writeBuf, lastStream, statusCode,
90  std::shared_ptr<folly::IOBuf>(debugData.release()));
91  }
92 
95  uint64_t));
101  size_t(folly::IOBufQueue&,
102  uint16_t,
103  std::shared_ptr<folly::IOBuf>));
106  uint16_t requestId,
107  std::unique_ptr<folly::IOBuf> authRequest) override {
109  writeBuf,
110  requestId,
111  std::shared_ptr<folly::IOBuf>(authRequest.release()));
112  }
114  size_t(folly::IOBufQueue&,
115  uint16_t,
116  std::shared_ptr<folly::IOBuf>));
119  uint16_t certId,
120  std::unique_ptr<folly::IOBuf> authenticator) override {
121  return generateCertificate(
122  writeBuf,
123  certId,
124  std::shared_ptr<folly::IOBuf>(authenticator.release()));
125  }
130  MOCK_METHOD3(
134  };
135 
137  public:
138  MOCK_METHOD2(onMessageBegin, void(HTTPCodec::StreamID, HTTPMessage*));
139  MOCK_METHOD3(onPushMessageBegin, void(HTTPCodec::StreamID,
141  HTTPMessage*));
142  MOCK_METHOD4(onExMessageBegin, void(HTTPCodec::StreamID,
144  bool,
145  HTTPMessage*));
146  MOCK_METHOD2(onHeadersComplete, void(HTTPCodec::StreamID,
147  std::shared_ptr<HTTPMessage>));
149  std::unique_ptr<HTTPMessage> msg) override {
150  onHeadersComplete(stream, std::shared_ptr<HTTPMessage>(msg.release()));
151  }
152  MOCK_METHOD3(onBody, void(HTTPCodec::StreamID,
153  std::shared_ptr<folly::IOBuf>, uint8_t));
155  std::unique_ptr<folly::IOBuf> chain, uint16_t padding) override {
156  onBody(stream, std::shared_ptr<folly::IOBuf>(chain.release()), padding);
157  }
158  MOCK_METHOD2(onChunkHeader, void(HTTPCodec::StreamID, size_t));
159  MOCK_METHOD1(onChunkComplete, void(HTTPCodec::StreamID));
160  MOCK_METHOD2(onTrailersComplete, void(HTTPCodec::StreamID,
161  std::shared_ptr<HTTPHeaders>));
163  std::unique_ptr<HTTPHeaders> trailers) override {
164  onTrailersComplete(stream,
165  std::shared_ptr<HTTPHeaders>(trailers.release()));
166  }
167  MOCK_METHOD2(onMessageComplete, void(HTTPCodec::StreamID, bool));
168  MOCK_METHOD3(onError, void(HTTPCodec::StreamID,
169  std::shared_ptr<HTTPException>, bool));
171  const HTTPException& exc,
172  bool newStream) override {
173  onError(stream,
174  std::shared_ptr<HTTPException>(new HTTPException(exc)),
175  newStream);
176  }
177  MOCK_METHOD5(onFrameHeader,
179  MOCK_METHOD2(onAbort, void(HTTPCodec::StreamID, ErrorCode));
180  MOCK_METHOD3(onGoaway,
181  void(uint64_t, ErrorCode, std::shared_ptr<folly::IOBuf>));
182  void onGoaway(uint64_t lastGoodStreamID, ErrorCode code,
183  std::unique_ptr<folly::IOBuf> debugData) override {
184  onGoaway(lastGoodStreamID, code,
185  std::shared_ptr<folly::IOBuf>(debugData.release()));
186  }
187  MOCK_METHOD1(onPingRequest, void(uint64_t));
188  MOCK_METHOD1(onPingReply, void(uint64_t));
189  MOCK_METHOD2(onWindowUpdate, void(HTTPCodec::StreamID, uint32_t));
190  MOCK_METHOD1(onSettings, void(const SettingsList&));
191  MOCK_METHOD0(onSettingsAck, void());
192  MOCK_METHOD2(onPriority, void(HTTPCodec::StreamID,
193  const HTTPMessage::HTTPPriority&));
194  MOCK_METHOD2(onCertificateRequest,
195  void(uint16_t, std::shared_ptr<folly::IOBuf>));
197  uint16_t requestId,
198  std::unique_ptr<folly::IOBuf> certRequestData) override {
199  onCertificateRequest(
200  requestId, std::shared_ptr<folly::IOBuf>(certRequestData.release()));
201  }
202  MOCK_METHOD2(onCertificate, void(uint16_t, std::shared_ptr<folly::IOBuf>));
203  void onCertificate(uint16_t certId,
204  std::unique_ptr<folly::IOBuf> certData) override {
205  onCertificate(certId, std::shared_ptr<folly::IOBuf>(certData.release()));
206  }
207  MOCK_METHOD4(onNativeProtocolUpgrade, bool(HTTPCodec::StreamID, CodecProtocol,
208  const std::string&,
209  HTTPMessage&));
210  MOCK_METHOD4(onGenerateFrameHeader,
212  MOCK_CONST_METHOD0(numOutgoingStreams, uint32_t());
213  MOCK_CONST_METHOD0(numIncomingStreams, uint32_t());
214 };
215 
216 #if defined(__clang__) && __clang_major__ >= 3 && __clang_minor__ >= 6
217 #pragma clang diagnostic pop
218 #endif
219 
220 }
MOCK_METHOD3(generateChunkHeader, size_t(folly::IOBufQueue &, HTTPCodec::StreamID, size_t))
virtual const HTTPSettings * getIngressSettings() const
Definition: HTTPCodec.h:657
virtual size_t onIngress(const folly::IOBuf &buf)=0
MOCK_METHOD4(generateGoaway, size_t(folly::IOBufQueue &, StreamID, ErrorCode, std::shared_ptr< folly::IOBuf >))
virtual size_t generatePingReply(folly::IOBufQueue &, uint64_t)
Definition: HTTPCodec.h:584
virtual bool closeOnEgressComplete() const =0
virtual StreamID createStream()=0
virtual HTTPSettings * getEgressSettings()
Definition: HTTPCodec.h:653
spdy::GoawayStatusCode statusCode
Definition: SPDYCodec.cpp:110
virtual bool supportsSessionFlowControl() const
Definition: HTTPCodec.h:374
MOCK_CONST_METHOD1(mapPriorityToDependency, HTTPCodec::StreamID(uint8_t))
virtual bool supportsPushTransactions() const =0
virtual void generateHeader(folly::IOBufQueue &writeBuf, StreamID stream, const HTTPMessage &msg, bool eom=false, HTTPHeaderSize *size=nullptr)=0
virtual void setCallback(Callback *callback)=0
size_t generateBody(folly::IOBufQueue &writeBuf, HTTPCodec::StreamID stream, std::unique_ptr< folly::IOBuf > chain, folly::Optional< uint8_t > padding, bool eom) override
Definition: MockHTTPCodec.h:57
virtual size_t generateChunkTerminator(folly::IOBufQueue &writeBuf, StreamID stream)=0
virtual CodecProtocol getProtocol() const =0
MOCK_CONST_METHOD0(getProtocol, CodecProtocol())
size_t generateCertificateRequest(folly::IOBufQueue &writeBuf, uint16_t requestId, std::unique_ptr< folly::IOBuf > authRequest) override
virtual void generatePushPromise(folly::IOBufQueue &, StreamID, const HTTPMessage &, StreamID, bool, HTTPHeaderSize *)
Definition: HTTPCodec.h:492
MOCK_METHOD6(generatePushPromise, void(folly::IOBufQueue &, HTTPCodec::StreamID, const HTTPMessage &, HTTPCodec::StreamID, bool eom, HTTPHeaderSize *))
virtual size_t generateRstStream(folly::IOBufQueue &writeBuf, StreamID stream, ErrorCode code)=0
virtual size_t generateTrailers(folly::IOBufQueue &writeBuf, StreamID stream, const HTTPHeaders &trailers)=0
MOCK_METHOD5(generateHeader, void(folly::IOBufQueue &, HTTPCodec::StreamID, const HTTPMessage &, bool eom, HTTPHeaderSize *))
virtual bool isWaitingToDrain() const =0
MOCK_METHOD0(createStream, HTTPCodec::StreamID())
void onCertificateRequest(uint16_t requestId, std::unique_ptr< folly::IOBuf > certRequestData) override
virtual void onIngressEOF()=0
virtual const std::string & getUserAgent() const =0
void writeBuf(const Buf &buf, folly::io::Appender &out)
virtual bool supportsStreamFlowControl() const
Definition: HTTPCodec.h:367
void onGoaway(uint64_t lastGoodStreamID, ErrorCode code, std::unique_ptr< folly::IOBuf > debugData) override
virtual size_t generateSettingsAck(folly::IOBufQueue &)
Definition: HTTPCodec.h:600
virtual size_t addPriorityNodes(PriorityQueue &, folly::IOBufQueue &, uint8_t)
Definition: HTTPCodec.h:696
virtual uint32_t getDefaultWindowSize() const
Definition: HTTPCodec.h:680
virtual size_t generateChunkHeader(folly::IOBufQueue &writeBuf, StreamID stream, size_t length)=0
virtual StreamID mapPriorityToDependency(uint8_t) const
Definition: HTTPCodec.h:706
void onError(HTTPCodec::StreamID stream, const HTTPException &exc, bool newStream) override
virtual void enableDoubleGoawayDrain()
Definition: HTTPCodec.h:665
virtual size_t generateEOM(folly::IOBufQueue &writeBuf, StreamID stream)=0
size_t generateCertificate(folly::IOBufQueue &writeBuf, uint16_t certId, std::unique_ptr< folly::IOBuf > authenticator) override
std::tuple< uint32_t, bool, uint8_t > HTTPPriority
Definition: HTTPMessage.h:592
std::vector< HTTPSetting > SettingsList
Definition: HTTPSettings.h:81
const char * string
Definition: Conv.cpp:212
void onHeadersComplete(HTTPCodec::StreamID stream, std::unique_ptr< HTTPMessage > msg) override
size_t generateGoaway(folly::IOBufQueue &writeBuf, StreamID lastStream, ErrorCode statusCode, std::unique_ptr< folly::IOBuf > debugData) override
Definition: MockHTTPCodec.h:85
virtual bool isReusable() const =0
uint64_t StreamID
Definition: HTTPCodec.h:49
virtual size_t generateWindowUpdate(folly::IOBufQueue &, StreamID, uint32_t)
Definition: HTTPCodec.h:610
virtual size_t generateSettings(folly::IOBufQueue &)
Definition: HTTPCodec.h:592
virtual bool isBusy() const =0
void onCertificate(uint16_t certId, std::unique_ptr< folly::IOBuf > certData) override
virtual void setParserPaused(bool paused)=0
void onBody(HTTPCodec::StreamID stream, std::unique_ptr< folly::IOBuf > chain, uint16_t padding) override
virtual size_t generatePingRequest(folly::IOBufQueue &)
Definition: HTTPCodec.h:576
virtual bool supportsParallelRequests() const =0
MOCK_METHOD1(setCallback, void(Callback *))
virtual TransportDirection getTransportDirection() const =0
void onTrailersComplete(HTTPCodec::StreamID stream, std::unique_ptr< HTTPHeaders > trailers) override
MOCK_METHOD2(generateChunkTerminator, size_t(folly::IOBufQueue &, HTTPCodec::StreamID))