26 folly::to<std::string>(
27 "IOBuf is ", negation ?
"not " :
"",
"'", expected,
"'")) {
28 auto iob = arg->clone();
29 auto br = iob->coalesce();
31 *result_listener <<
"'" << actual <<
"'";
32 return actual == expected;
40 responseHandler_ = std::make_unique<MockResponseHandler>(requestHandler_);
45 Mock::VerifyAndClear(requestHandler_);
46 Mock::VerifyAndClear(responseHandler_.get());
48 delete requestHandler_;
55 std::unique_ptr<ZlibStreamDecompressor>
zd_;
64 std::unique_ptr<folly::IOBuf> originalResponseBody,
66 uint32_t minimumCompressionSize = 1) {
69 bool isResponseChunked = originalResponseBody->
isChained();
73 if (isResponseChunked && expectCompression) {
83 .WillOnce(
DoAll(SaveArg<0>(&downstream_),
Return()));
90 if (expectCompression) {
104 if (isResponseChunked) {
106 EXPECT_CALL(*responseHandler_, sendChunkHeader(
_)).Times(chunkCount);
107 EXPECT_CALL(*responseHandler_, sendChunkTerminator()).Times(chunkCount);
109 EXPECT_CALL(*responseHandler_, sendChunkHeader(
_)).Times(0);
110 EXPECT_CALL(*responseHandler_, sendChunkTerminator()).Times(0);
114 std::unique_ptr<folly::IOBuf> responseBody;
117 .WillRepeatedly(
DoAll(
118 Invoke([&](std::shared_ptr<folly::IOBuf> body) {
120 std::unique_ptr<folly::IOBuf> processedBody;
122 if (expectCompression) {
125 <<
"Failed to decompress body. r=" << zd_->
getStatus();
128 body->data(), body->length(), 0, 0);
139 EXPECT_CALL(*responseHandler_, sendEOM()).Times(1);
147 std::set<std::string> compressibleTypes = {
"text/html"};
148 auto filterFactory = std::make_unique<ZlibServerFilterFactory>(
149 compressionLevel, minimumCompressionSize, compressibleTypes);
151 auto filter = filterFactory->onRequest(requestHandler_, &msg);
152 filter->setResponseHandler(responseHandler_.get());
159 if (isResponseChunked) {
167 crtBuf = originalResponseBody.get();
171 crtBuf = crtBuf->
next();
172 }
while (crtBuf != originalResponseBody.get());
186 filter->requestComplete();
188 EXPECT_THAT(responseBody, IOBufEquals(originalRequestBody));
194 std::vector<std::string>
const& bodyStrings) {
196 std::unique_ptr<folly::IOBuf> responseBodyChain;
198 for (
auto&
s : bodyStrings) {
200 if (responseBodyChain) {
207 return responseBodyChain;
214 exercise_compression(
true,
225 std::vector<std::string>
chunks = {
"Hello",
" World"};
227 exercise_compression(
true,
233 createResponseChain(chunks));
239 exercise_compression(
true,
251 exercise_compression(
true,
264 exercise_compression(
true,
276 exercise_compression(
true,
288 exercise_compression(
false,
300 exercise_compression(
false,
313 exercise_compression(
false,
325 exercise_compression(
false,
338 exercise_compression(
false,
353 std::vector<std::string>
chunks = {
"Hello",
" World"};
355 exercise_compression(
true,
361 createResponseChain(chunks),
370 exercise_compression(
true,
378 requestBody.length());
388 uint32_t minimumCompressionSize = 0;
396 .WillOnce(
DoAll(SaveArg<0>(&downstream_),
Return()));
414 EXPECT_CALL(*responseHandler_, sendEOM()).Times(1);
421 std::set<std::string> compressibleTypes = {
"text/html"};
422 auto filterFactory = std::make_unique<ZlibServerFilterFactory>(
423 compressionLevel, minimumCompressionSize, compressibleTypes);
425 auto filter = filterFactory->onRequest(requestHandler_, &msg);
426 filter->setResponseHandler(responseHandler_.get());
438 filter->requestComplete();
ResponseBuilder & status(uint16_t code, const std::string &message)
void exercise_compression(bool expectCompression, std::string url, std::string acceptedEncoding, std::string expectedEncoding, std::string originalRequestBody, std::string responseContentType, std::unique_ptr< folly::IOBuf > originalResponseBody, int32_t compressionLevel=4, uint32_t minimumCompressionSize=1)
PUSHMI_INLINE_VAR constexpr detail::filter_fn filter
constexpr detail::Map< Move > move
std::unique_ptr< IOBuf > clone() const
size_t countChainElements() const
ResponseBuilder & body(std::unique_ptr< folly::IOBuf > bodyIn)
std::unique_ptr< folly::IOBuf > createResponseChain(std::vector< std::string > const &bodyStrings)
std::unique_ptr< folly::IOBuf > decompress(const folly::IOBuf *in)
std::unique_ptr< ZlibStreamDecompressor > zd_
bool checkForHeaderToken(const HTTPHeaderCode headerCode, char const *token, bool caseSensitive) const
bool getIsChunked() const
PolymorphicAction< internal::InvokeAction< FunctionImpl > > Invoke(FunctionImpl function_impl)
ResponseBuilder & header(const std::string &headerIn, const T &value)
MockRequestHandler * requestHandler_
ssize_t send(NetworkSocket s, const void *buf, size_t len, int flags)
std::unique_ptr< IOBuf > cloneOne() const
HTTPHeaders & getHeaders()
std::unique_ptr< MockResponseHandler > responseHandler_
void prependChain(std::unique_ptr< IOBuf > &&iobuf)
#define EXPECT_TRUE(condition)
#define EXPECT_THAT(value, matcher)
internal::DoBothAction< Action1, Action2 > DoAll(Action1 a1, Action2 a2)
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
TEST_F(HeaderTableTests, IndexTranslation)
#define ASSERT_NO_FATAL_FAILURE(statement)
#define ASSERT_FALSE(condition)
#define EXPECT_FALSE(condition)
static std::unique_ptr< IOBuf > copyBuffer(const void *buf, std::size_t size, std::size_t headroom=0, std::size_t minTailroom=0)
MATCHER_P(PtrBufHasLen, n,"")
internal::ReturnAction< R > Return(R value)