32 std::unique_ptr<HTTPMessage> msg)
override {
38 std::unique_ptr<folly::IOBuf> chain,
46 std::unique_ptr<HTTPHeaders> )
override {}
55 LOG(
ERROR) <<
"parse error";
63 std::unique_ptr<HTTPMessage>
msg_;
67 string req(
"GET /yeah HTTP/1.1\nHost: www.facebook.com\n\n");
71 TEST(HTTP1xCodecTest, TestSimpleHeaders) {
82 TEST(HTTP1xCodecTest, Test09Req) {
98 TEST(HTTP1xCodecTest, Test09ReqVers) {
110 TEST(HTTP1xCodecTest, Test09Resp) {
122 string(
"iamtheverymodelofamodernmajorgeneral"));
131 TEST(HTTP1xCodecTest, TestBadHeaders) {
136 string(
"GET /yeah HTTP/1.1\nUser-Agent: Mozilla/5.0 Version/4.0 " 137 "\x10i\xC7n tho\xA1iSafari/534.30]"));
141 std::shared_ptr<HTTPException>
error,
143 EXPECT_EQ(error->getHttpStatusCode(), 400);
148 TEST(HTTP1xCodecTest, TestHeadRequestChunkedResponse) {
156 "HEAD /www.facebook.com HTTP/1.1\nHost: www.facebook.com\n\n");
168 auto respStr = respBuf.
move()->moveToFbString();
169 EXPECT_TRUE(respStr.find(
"0\r\n") == string::npos);
172 TEST(HTTP1xCodecTest, TestGetRequestChunkedResponse) {
180 "GET /www.facebook.com HTTP/1.1\nHost: www.facebook.com\n\n");
195 string resp1(
"Hello");
205 ASSERT_EQ(
"5\r\nHello\r\n", bodyFromBuf->moveToFbString());
211 ASSERT_EQ(
"0\r\n\r\n", bodyFromBuf->moveToFbString());
215 string req(
"GET /aha HTTP/1.1\n");
220 string req(
"Host: m.facebook.com\nAccept-Encoding: meflate\n\n");
224 TEST(HTTP1xCodecTest, TestChunkedHeaders) {
229 for (
int i = 0;
i < 3;
i++) {
239 buffer1->length() + buffer2->length());
243 TEST(HTTP1xCodecTest, TestChunkedUpstream) {
250 msg.
setURL(
"https://www.facebook.com/");
261 string req1(
"Hello");
264 string req2(
"World");
271 ASSERT_EQ(
"5\r\nHello\r\n", bodyFromBuf->moveToFbString());
278 ASSERT_EQ(
"5\r\nWorld\r\n0\r\n\r\n", eomFromBuf->moveToFbString());
281 TEST(HTTP1xCodecTest, TestBadPost100) {
322 "POST /www.facebook.com HTTP/1.1\r\nHost: www.facebook.com\r\n" 323 "Expect: 100-Continue\r\nContent-Length: 5\r\n\r\nabcdefghij");
327 TEST(HTTP1xCodecTest, TestMultipleIdenticalContentLengthHeaders) {
335 "POST /www.facebook.com HTTP/1.1\r\nHost: www.facebook.com\r\n" 336 "Content-Length: 5\r\nContent-Length: 5\r\n\r\n");
346 TEST(HTTP1xCodecTest, TestMultipleDistinctContentLengthHeaders) {
354 "POST /www.facebook.com HTTP/1.1\r\nHost: www.facebook.com\r\n" 355 "Content-Length: 5\r\nContent-Length: 6\r\n\r\n");
365 TEST(HTTP1xCodecTest, TestCorrectTransferEncodingHeader) {
373 "POST /www.facebook.com HTTP/1.1\r\nHost: www.facebook.com\r\n" 374 "Transfer-Encoding: chunked\r\n\r\n");
383 TEST(HTTP1xCodecTest, TestFoldedTransferEncodingHeader) {
391 "POST /www.facebook.com HTTP/1.1\r\nHost: www.facebook.com\r\n" 392 "Transfer-Encoding: \r\n chunked\r\nContent-Length: 8\r\n\r\n");
402 TEST(HTTP1xCodecTest, TestBadTransferEncodingHeader) {
409 "POST /www.facebook.com HTTP/1.1\r\nHost: www.facebook.com\r\n" 410 "Transfer-Encoding: chunked, zorg\r\n\r\n");
420 TEST(HTTP1xCodecTest, Test1xxConnectionHeader) {
449 TEST(HTTP1xCodecTest, TestChainedBody) {
462 "POST /test.php HTTP/1.1\r\nHost: www.test.com\r\n" 463 "Content-Length: 10\r\n\r\nabcde"));
466 while (!reqQueue.
empty()) {
468 if (processed == 0) {
478 TEST(HTTP1xCodecTest, TestIgnoreUpstreamUpgrade) {
485 "HTTP/1.1 200 OK\r\n" 486 "Connection: close\r\n" 487 "Upgrade: h2,h2c\r\n" 498 TEST(HTTP1xCodecTest, WebsocketUpgrade) {
517 auto& headers = downStreamCallbacks.
msg_->getHeaders();
529 headers = upstreamCallbacks.
msg_->getHeaders();
530 auto ws_accept_header =
535 TEST(HTTP1xCodecTest, WebsocketUpgradeKeyError) {
549 "HTTP/1.1 200 OK\r\n" 550 "Connection: upgrade\r\n" 551 "Upgrade: websocket\r\n" 558 TEST(HTTP1xCodecTest, WebsocketUpgradeHeaderSet) {
573 auto headers = callbacks.
msg_->getHeaders();
578 TEST(HTTP1xCodecTest, WebsocketConnectionHeader) {
586 "key should change");
588 "this should not be found");
596 auto headers = callbacks.
msg_->getHeaders();
599 EXPECT_NE(ws_sec_key,
"key should change");
611 "upgrade, keep-alive");
614 TEST(HTTP1xCodecTest, TrailersAndEomAreNotGeneratedWhenNonChunked) {
626 msg.
setURL(
"https://www.facebook.com/");
634 trailers.
add(
"X-Test-Trailer",
"test");
640 public TestWithParam<std::pair<std::list<string>, string>> {
653 auto val = GetParam();
654 for (
auto header:
val.first) {
661 auto& headers = callbacks.
msg_->getHeaders();
673 {
"foo",
"bar",
"close",
"baz" },
"foo, bar, baz, close"),
676 {
"foo",
"bar, close",
"baz" },
"foo, bar, baz, close"),
679 {
" foo",
"bar, close ",
" baz " },
"foo, bar, baz, close"),
682 {
"foo",
"bar, boo",
"baz" },
"foo, bar, boo, baz, keep-alive"),
685 {
"foo",
"keep-alive, boo",
"close" },
"foo, boo, close"),
688 {
"foo",
"upgrade, boo",
"baz" },
"foo, upgrade, boo, baz, keep-alive")
std::unique_ptr< folly::IOBuf > split(size_t n)
std::vector< uint8_t > buffer(kBufferSize+16)
size_t generateTrailers(folly::IOBufQueue &writeBuf, StreamID txn, const HTTPHeaders &trailers) override
const folly::IOBuf * front() const
static const folly::Optional< uint8_t > NoPadding
void append(std::unique_ptr< folly::IOBuf > &&buf, bool pack=false)
constexpr size_t headerSize()
size_t chainLength() const
void onChunkHeader(HTTPCodec::StreamID, size_t) override
void onPushMessageBegin(HTTPCodec::StreamID, HTTPCodec::StreamID, HTTPMessage *) override
#define EXPECT_NO_THROW(statement)
#define ASSERT_EQ(val1, val2)
std::unique_ptr< HTTPException > lastParseError
void setStatusMessage(T &&msg)
void generateHeader(folly::IOBufQueue &writeBuf, StreamID txn, const HTTPMessage &msg, bool eom=false, HTTPHeaderSize *size=nullptr) override
#define EXPECT_EQ(val1, val2)
void onChunkComplete(HTTPCodec::StreamID) override
constexpr detail::Map< Move > move
std::unique_ptr< folly::IOBuf > move()
const HTTPHeaderSize & getIngressHeaderSize() const
TEST(HTTP1xCodecTest, TestSimpleHeaders)
void onBody(HTTPCodec::StreamID, std::unique_ptr< folly::IOBuf > chain, uint16_t) override
requires And< SemiMovable< VN >... > &&SemiMovable< E > auto error(E e)
PolymorphicAction< internal::InvokeWithoutArgsAction< FunctionImpl > > InvokeWithoutArgs(FunctionImpl function_impl)
unique_ptr< folly::IOBuf > getChunkedRequest1st()
void onHeadersComplete(HTTPCodec::StreamID, std::unique_ptr< HTTPMessage > msg) override
void setIsChunked(bool chunked)
unique_ptr< folly::IOBuf > getChunkedRequest2nd()
constexpr auto size(C const &c) -> decltype(c.size())
void writeBuf(const Buf &buf, folly::io::Appender &out)
static Options cacheChainLength()
PolymorphicAction< internal::InvokeAction< FunctionImpl > > Invoke(FunctionImpl function_impl)
void setCallback(Callback *callback) override
static std::string decode(const std::string &b64message, int padding)
unique_ptr< folly::IOBuf > getSimpleRequestData()
size_t onIngress(const folly::IOBuf &buf) override
void onTrailersComplete(HTTPCodec::StreamID, std::unique_ptr< HTTPHeaders >) override
HTTPHeaders & getHeaders()
void onMessageBegin(HTTPCodec::StreamID, HTTPMessage *) override
void setMethod(HTTPMethod method)
std::size_t computeChainDataLength() const
#define EXPECT_TRUE(condition)
const std::string empty_string
#define ON_CALL(obj, call)
HTTPHeaderSize headerSize
void onMessageComplete(HTTPCodec::StreamID, bool) override
#define EXPECT_NE(val1, val2)
void setParserPaused(bool paused) override
void setHTTPVersion(uint8_t major, uint8_t minor)
void trimStart(size_t amount)
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
void setEgressWebsocketUpgrade()
StreamID createStream() override
static std::unique_ptr< IOBuf > copyBuffer(const void *buf, std::size_t size, std::size_t headroom=0, std::size_t minTailroom=0)
size_t generateEOM(folly::IOBufQueue &writeBuf, StreamID txn) override
void onError(HTTPCodec::StreamID, const HTTPException &, bool) override
INSTANTIATE_TEST_CASE_P(ValueTest, RFC1867CR,::testing::Values(string("zyx\r\nwvu", 8), string("\rzyxwvut", 8), string("zyxwvut\r", 8), string("\nzyxwvut", 8), string("zyxwvut\n", 8), string("\r\n\r\n\r\n\r\n", 8), string("\r\r\r\r\r\r\r\r", 8)))
void onIngressEOF() override
std::unique_ptr< HTTPMessage > msg_
size_t generateBody(folly::IOBufQueue &writeBuf, StreamID txn, std::unique_ptr< folly::IOBuf > chain, folly::Optional< uint8_t > padding, bool eom) override
void setStatusCode(uint16_t status)