本文整理汇总了C++中HTTPMessage::getMethodString方法的典型用法代码示例。如果您正苦于以下问题:C++ HTTPMessage::getMethodString方法的具体用法?C++ HTTPMessage::getMethodString怎么用?C++ HTTPMessage::getMethodString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HTTPMessage
的用法示例。
在下文中一共展示了HTTPMessage::getMethodString方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
TEST(HTTPMessage, TestMethod) {
HTTPMessage msg;
msg.setMethod(HTTPMethod::GET);
EXPECT_EQ("GET", msg.getMethodString());
EXPECT_EQ(HTTPMethod::GET == msg.getMethod(), true);
msg.setMethod("FOO");
EXPECT_EQ("FOO", msg.getMethodString());
EXPECT_EQ(boost::none == msg.getMethod(), true);
msg.setMethod(HTTPMethod::CONNECT);
EXPECT_EQ("CONNECT", msg.getMethodString());
EXPECT_EQ(HTTPMethod::CONNECT == msg.getMethod(), true);
}
示例2: generateHeaderChrome
/**
* Mostly ripped from HTTP2Codec::generateHeader. This writes out frames
* like Chrome does, breaking on 1024 - frame header, with some of the not
* needed cases removed. It's specialized to write only a single continuation
* frame with optionally malformed length
*/
void generateHeaderChrome(HPACKCodec09& headerCodec,
folly::IOBufQueue& writeBuf,
HTTPCodec::StreamID stream,
const HTTPMessage& msg,
HTTPCodec::StreamID assocStream,
bool eom,
HTTPHeaderSize* size,
bool malformed) {
VLOG(4) << "generating " << ((assocStream != 0) ? "PUSH_PROMISE" : "HEADERS")
<< " for stream=" << stream;
std::vector<proxygen::compress::Header> allHeaders;
const string& method = msg.getMethodString();
const string& scheme = (msg.isSecure() ? http2::kHttps : http2::kHttp);
const string& path = msg.getURL();
const HTTPHeaders& headers = msg.getHeaders();
const string& host = headers.getSingleOrEmpty(HTTP_HEADER_HOST);
allHeaders.emplace_back(http2::kMethod, method);
allHeaders.emplace_back(http2::kScheme, scheme);
allHeaders.emplace_back(http2::kPath, path);
if (!host.empty()) {
allHeaders.emplace_back(http2::kAuthority, host);
}
// Add the HTTP headers supplied by the caller, but skip
// any per-hop headers that aren't supported in HTTP/2.
msg.getHeaders().forEachWithCode(
[&] (HTTPHeaderCode code,
const string& name,
const string& value) {
// Note this code will not drop headers named by Connection. That's the
// caller's job
// see HTTP/2 spec, 8.1.2
DCHECK(name != "TE" || value == "trailers");
if ((name.size() > 0 && name[0] != ':') &&
code != HTTP_HEADER_HOST) {
allHeaders.emplace_back(code, name, value);
}
});
headerCodec.setEncodeHeadroom(http2::kFrameHeadersBaseMaxSize);
auto out = headerCodec.encode(allHeaders);
if (size) {
*size = headerCodec.getEncodedSize();
}
IOBufQueue queue(IOBufQueue::cacheChainLength());
queue.append(std::move(out));
if (queue.chainLength() > 0) {
auto chunk = queue.split(std::min((size_t)(1024 - 14),
queue.chainLength()));
bool endHeaders = queue.chainLength() == 0;
CHECK(assocStream == 0);
http2::writeHeaders(writeBuf,
std::move(chunk),
stream,
http2::PriorityUpdate({0, false, 16}),
http2::kNoPadding,
eom,
endHeaders);
while (!endHeaders) {
CHECK(queue.chainLength() == 1015);
chunk = queue.split(std::min(size_t(1024 - http2::kFrameHeaderSize),
queue.chainLength()));
endHeaders = queue.chainLength() == 0;
CHECK(endHeaders);
VLOG(4) << "generating CONTINUATION for stream=" << stream;
writeFrameHeaderManual(writeBuf,
malformed ? 1024 : chunk->computeChainDataLength(),
9,
http2::END_HEADERS,
stream);
writeBuf.append(std::move(chunk));
}
}
}