本文整理汇总了C++中HTTPMessage::setIsChunked方法的典型用法代码示例。如果您正苦于以下问题:C++ HTTPMessage::setIsChunked方法的具体用法?C++ HTTPMessage::setIsChunked怎么用?C++ HTTPMessage::setIsChunked使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HTTPMessage
的用法示例。
在下文中一共展示了HTTPMessage::setIsChunked方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getChunkedPostRequest
HTTPMessage getChunkedPostRequest() {
HTTPMessage req;
req.setMethod("POST");
req.setURL<string>("/");
req.setHTTPVersion(1, 1);
req.setIsChunked(true);
req.getHeaders().set(HTTP_HEADER_HOST, "www.foo.com");
req.getHeaders().set(HTTP_HEADER_TRANSFER_ENCODING, "chunked");
return req;
}
示例2: codec
TEST(HTTP1xCodecTest, TestGetRequestChunkedResponse) {
HTTP1xCodec codec(TransportDirection::DOWNSTREAM);
HTTP1xCodecCallback callbacks;
codec.setCallback(&callbacks);
auto txnID = codec.createStream();
// Generate a GET request
auto reqBuf = folly::IOBuf::copyBuffer(
"GET /www.facebook.com HTTP/1.1\nHost: www.facebook.com\n\n");
codec.onIngress(*reqBuf);
EXPECT_EQ(callbacks.headersComplete, 1);
// Generate chunked response with body
HTTPMessage resp;
resp.setHTTPVersion(1, 1);
resp.setStatusCode(200);
resp.setIsChunked(true);
resp.getHeaders().set(HTTP_HEADER_TRANSFER_ENCODING, "chunked");
folly::IOBufQueue respBuf(folly::IOBufQueue::cacheChainLength());
codec.generateHeader(respBuf, txnID, resp, 0, false);
auto headerFromBuf = respBuf.split(respBuf.chainLength());
string resp1("Hello");
auto body1 = folly::IOBuf::copyBuffer(resp1);
string resp2("");
auto body2 = folly::IOBuf::copyBuffer(resp2);
codec.generateBody(respBuf, txnID, std::move(body1), HTTPCodec::NoPadding,
false);
auto bodyFromBuf = respBuf.split(respBuf.chainLength());
ASSERT_EQ("5\r\nHello\r\n", bodyFromBuf->moveToFbString());
codec.generateBody(respBuf, txnID, std::move(body2), HTTPCodec::NoPadding,
true);
bodyFromBuf = respBuf.split(respBuf.chainLength());
ASSERT_EQ("0\r\n\r\n", bodyFromBuf->moveToFbString());
}