本文整理汇总了C++中HTTPMessage::setHTTPVersion方法的典型用法代码示例。如果您正苦于以下问题:C++ HTTPMessage::setHTTPVersion方法的具体用法?C++ HTTPMessage::setHTTPVersion怎么用?C++ HTTPMessage::setHTTPVersion使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HTTPMessage
的用法示例。
在下文中一共展示了HTTPMessage::setHTTPVersion方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: upstream
TEST(HTTP1xCodecTest, Test1xxConnectionHeader) {
HTTP1xCodec upstream(TransportDirection::UPSTREAM);
HTTP1xCodec downstream(TransportDirection::DOWNSTREAM);
HTTP1xCodecCallback callbacks;
upstream.setCallback(&callbacks);
HTTPMessage resp;
resp.setStatusCode(100);
resp.setHTTPVersion(1, 1);
resp.getHeaders().add(HTTP_HEADER_CONNECTION, "Upgrade");
folly::IOBufQueue writeBuf(folly::IOBufQueue::cacheChainLength());
auto streamID = downstream.createStream();
downstream.generateHeader(writeBuf, streamID, resp);
upstream.onIngress(*writeBuf.front());
EXPECT_EQ(callbacks.headersComplete, 1);
EXPECT_EQ(
callbacks.msg_->getHeaders().getSingleOrEmpty(HTTP_HEADER_CONNECTION),
"Upgrade");
resp.setStatusCode(200);
resp.getHeaders().remove(HTTP_HEADER_CONNECTION);
resp.getHeaders().add(HTTP_HEADER_CONTENT_LENGTH, "0");
writeBuf.move();
downstream.generateHeader(writeBuf, streamID, resp);
upstream.onIngress(*writeBuf.front());
EXPECT_EQ(callbacks.headersComplete, 2);
EXPECT_EQ(
callbacks.msg_->getHeaders().getSingleOrEmpty(HTTP_HEADER_CONNECTION),
"keep-alive");
}
示例2: getGetRequest
HTTPMessage getGetRequest(const std::string& url) {
HTTPMessage req;
req.setMethod("GET");
req.setURL(url);
req.setHTTPVersion(1, 1);
req.getHeaders().set(HTTP_HEADER_HOST, "www.foo.com");
return req;
}
示例3: getPostRequest
HTTPMessage getPostRequest() {
HTTPMessage req;
req.setMethod("POST");
req.setURL<string>("/");
req.setHTTPVersion(1, 1);
req.getHeaders().set(HTTP_HEADER_HOST, "www.foo.com");
req.getHeaders().set(HTTP_HEADER_CONTENT_LENGTH, "200");
return req;
}
示例4: 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;
}
示例5: getPostRequest
HTTPMessage getPostRequest(uint32_t contentLength) {
HTTPMessage req;
req.setMethod("POST");
req.setURL<string>("/");
req.setHTTPVersion(1, 1);
req.getHeaders().set(HTTP_HEADER_HOST, "www.foo.com");
req.getHeaders().set(HTTP_HEADER_CONTENT_LENGTH,
folly::to<string>(contentLength));
return req;
}
示例6: getBigGetRequest
HTTPMessage getBigGetRequest(const std::string& url) {
HTTPMessage req;
req.setMethod("GET");
req.setURL(url);
req.setHTTPVersion(1, 1);
req.getHeaders().set(HTTP_HEADER_HOST, "www.foo.com");
req.getHeaders().add(HTTP_HEADER_USER_AGENT, "coolio");
req.getHeaders().add(
"x-huge-header",
std::string(http2::kMaxFramePayloadLengthMin, '!'));
return req;
}
示例7: sendErrorResponse
void ProxygenTransport::sendErrorResponse(uint32_t code) noexcept {
HTTPMessage response;
response.setHTTPVersion(1, 1);
response.setStatusCode(code);
response.setStatusMessage(HTTPMessage::getDefaultReason(code));
response.getHeaders().add(HTTP_HEADER_CONNECTION, "close");
CHECK(!m_sendStarted);
m_sendStarted = true;
m_sendEnded = true;
m_responseCode = code;
m_responseCodeInfo = response.getStatusMessage();
m_server->onRequestError(this);
m_clientTxn->sendHeaders(response);
m_clientTxn->sendEOM();
}
示例8: VLOG
bool
HTTPDownstreamSession::onNativeProtocolUpgrade(
HTTPCodec::StreamID streamID, CodecProtocol protocol,
const std::string& protocolString,
HTTPMessage& msg) {
VLOG(4) << *this << " onNativeProtocolUpgrade streamID=" << streamID <<
" protocol=" << protocolString;
auto txn = findTransaction(streamID);
CHECK(txn);
if (txn->canSendHeaders()) {
// Create the new Codec
auto codec = HTTPCodecFactory::getCodec(protocol,
TransportDirection::DOWNSTREAM);
CHECK(codec);
if (!codec->onIngressUpgradeMessage(msg)) {
VLOG(4) << *this << " codec rejected upgrade";
return false;
}
// Send a 101 Switching Protocols message while we still have HTTP codec
// Note: it's possible that the client timed out waiting for a
// 100-continue and ended up here first. In this case the 100 may go
// out in the new protocol
HTTPMessage switchingProtos;
switchingProtos.setHTTPVersion(1, 1);
switchingProtos.setStatusCode(101);
switchingProtos.setStatusMessage("Switching Protocols");
switchingProtos.getHeaders().set(HTTP_HEADER_UPGRADE, protocolString);
txn->sendHeaders(switchingProtos);
// no sendEOM for 1xx
// This will actually switch the protocol
bool ret = HTTPSession::onNativeProtocolUpgradeImpl(
streamID, std::move(codec), protocolString);
if (ret) {
codec_->addPriorityNodes(txnEgressQueue_, writeBuf_, 0);
}
return ret;
} else {
VLOG(4) << *this << " plaintext upgrade failed due to early response";
return false;
}
}
示例9: codec
TEST(HTTP1xCodecTest, Test09Resp) {
HTTP1xCodec codec(TransportDirection::UPSTREAM);
HTTP1xCodecCallback callbacks;
HTTPMessage req;
auto id = codec.createStream();
req.setHTTPVersion(0, 9);
req.setMethod(HTTPMethod::GET);
req.setURL("/");
codec.setCallback(&callbacks);
folly::IOBufQueue buf;
codec.generateHeader(buf, id, req, 0, true);
auto buffer = folly::IOBuf::copyBuffer(
string("iamtheverymodelofamodernmajorgeneral"));
codec.onIngress(*buffer);
EXPECT_EQ(callbacks.headersComplete, 1);
EXPECT_EQ(callbacks.bodyLen, buffer->computeChainDataLength());
EXPECT_EQ(callbacks.messageComplete, 0);
codec.onIngressEOF();
EXPECT_EQ(callbacks.messageComplete, 1);
}
示例10: onHeadersComplete
void ProxygenTransport::onHeadersComplete(
unique_ptr<HTTPMessage> msg) noexcept {
Timer::GetMonotonicTime(m_requestStart);
m_request = std::move(msg);
if (m_request->isSecure()) {
setSSL();
}
m_request->dumpMessage(4);
auto method = m_request->getMethod();
const auto& methodStr = m_request->getMethodString();
if (method == HTTPMethod::GET) {
m_method = Transport::Method::GET;
} else if (method == HTTPMethod::POST ||
s_post_methods.find(methodStr) != s_post_methods.end()) {
m_method = Transport::Method::POST;
} else if (method == HTTPMethod::HEAD) {
m_method = Transport::Method::HEAD;
} else if (method == HTTPMethod::CONNECT) {
sendErrorResponse(400 /* Bad Request */);
return;
} else {
// looks like proxygen HTTP parser understands a few more methods
// than libevent:
// TRACE, COPY, MOVE, MKACTIVITY, CHECKOUT, MERGE, MSEARCH, NOTIFY,
// SUBSCRIBE, UNSUBSCRIBE, PATCH
sendErrorResponse(400 /* Bad Request */);
return;
}
m_extended_method = methodStr.c_str();
const auto& headers = m_request->getHeaders();
headers.forEach([&] (const std::string &header, const std::string &val) {
m_requestHeaders[header.c_str()].push_back(val.c_str());
});
if (m_method == Transport::Method::POST && m_request->isHTTP1_1()) {
const std::string& expectation =
headers.getSingleOrEmpty(HTTP_HEADER_EXPECT);
if (!expectation.empty()) {
bool sendEom = false;
HTTPMessage response;
if (!boost::iequals(expectation, "100-continue")) {
response.setStatusCode(417);
response.setStatusMessage(HTTPMessage::getDefaultReason(417));
response.getHeaders().add(HTTP_HEADER_CONNECTION, "close");
sendEom = true;
} else {
response.setStatusCode(100);
response.setStatusMessage(HTTPMessage::getDefaultReason(100));
}
response.setHTTPVersion(1, 1);
response.dumpMessage(4);
m_clientTxn->sendHeaders(response);
if (sendEom) {
m_responseCode = response.getStatusCode();
m_responseCodeInfo = response.getStatusMessage();
m_server->onRequestError(this);
m_clientTxn->sendEOM();
// this object is no longer valid
return;
}
}
}
if (!bufferRequest()) {
m_enqueued = true;
m_server->onRequest(shared_from_this());
} // otherwise we wait for EOM
}
示例11:
TEST(HTTPMessage, TestKeepaliveCheck) {
{
HTTPMessage msg;
msg.setHTTPVersion(1, 0);
EXPECT_FALSE(msg.computeKeepalive());
}
{
HTTPMessage msg;
msg.setHTTPVersion(1, 1);
EXPECT_TRUE(msg.computeKeepalive());
}
{
HTTPMessage msg;
msg.setHTTPVersion(1, 1);
msg.getHeaders().add("Connection", "close");
EXPECT_FALSE(msg.computeKeepalive());
}
{
HTTPMessage msg;
msg.setHTTPVersion(1, 1);
msg.getHeaders().add("Connection", "ClOsE");
EXPECT_FALSE(msg.computeKeepalive());
}
{
HTTPMessage msg;
msg.setHTTPVersion(1, 1);
msg.getHeaders().add("Connection", "foo,bar");
EXPECT_TRUE(msg.computeKeepalive());
}
{
HTTPMessage msg;
msg.setHTTPVersion(1, 1);
msg.getHeaders().add("Connection", "foo,bar");
msg.getHeaders().add("Connection", "abc,CLOSE,def");
msg.getHeaders().add("Connection", "xyz");
EXPECT_FALSE(msg.computeKeepalive());
}
{
HTTPMessage msg;
msg.setHTTPVersion(1, 1);
msg.getHeaders().add("Connection", "foo,bar");
msg.getHeaders().add("Connection", "abc , CLOSE , def");
msg.getHeaders().add("Connection", "xyz");
EXPECT_FALSE(msg.computeKeepalive());
}
{
HTTPMessage msg;
msg.setHTTPVersion(1, 1);
msg.getHeaders().add("Connection", " close ");
EXPECT_FALSE(msg.computeKeepalive());
}
{
HTTPMessage msg;
msg.setHTTPVersion(1, 1);
msg.getHeaders().add("Connection", ", close ");
EXPECT_FALSE(msg.computeKeepalive());
}
{
HTTPMessage msg;
msg.setHTTPVersion(1, 1);
msg.getHeaders().add("Connection", " close , ");
EXPECT_FALSE(msg.computeKeepalive());
}
{
HTTPMessage msg;
msg.setHTTPVersion(1, 0);
msg.getHeaders().add("Connection", "Keep-Alive");
EXPECT_TRUE(msg.computeKeepalive());
}
{
HTTPMessage msg;
msg.setHTTPVersion(1, 0);
msg.getHeaders().add("Connection", "keep-alive");
EXPECT_TRUE(msg.computeKeepalive());
}
{
HTTPMessage msg;
msg.setHTTPVersion(1, 0);
msg.getHeaders().add("Connection", "keep-alive");
msg.getHeaders().add("Connection", "close");
EXPECT_FALSE(msg.computeKeepalive());
}
}