当前位置: 首页>>代码示例>>C++>>正文


C++ HTTPMessage::setMethod方法代码示例

本文整理汇总了C++中HTTPMessage::setMethod方法的典型用法代码示例。如果您正苦于以下问题:C++ HTTPMessage::setMethod方法的具体用法?C++ HTTPMessage::setMethod怎么用?C++ HTTPMessage::setMethod使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在HTTPMessage的用法示例。


在下文中一共展示了HTTPMessage::setMethod方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
开发者ID:abhiguru,项目名称:proxygen,代码行数:15,代码来源:HTTPMessageTest.cpp

示例2: egressCodec

// Test serializing and deserializing a header that has many values
TEST(SPDYCodecTest, HeaderWithManyValues) {
  const std::string kMultiValued = "X-Multi-Valued";
  const unsigned kNumValues = 1000;

  FakeHTTPCodecCallback callbacks;
  SPDYCodec egressCodec(TransportDirection::UPSTREAM,
                        SPDYVersion::SPDY3);
  SPDYCodec ingressCodec(TransportDirection::DOWNSTREAM,
                         SPDYVersion::SPDY3);
  ingressCodec.setCallback(&callbacks);

  HTTPMessage req;
  req.setMethod("GET");
  req.getHeaders().set("HOST", "www.foo.com");
  req.setURL("https://www.foo.com");
  for (unsigned i = 0; i < kNumValues; ++i) {
    req.getHeaders().add(kMultiValued, folly::to<string>("Value", i));
  }
  auto syn = getSynStream(egressCodec, 1, req);
  ingressCodec.onIngress(*syn);
  EXPECT_EQ(callbacks.messageBegin, 1);
  EXPECT_EQ(callbacks.headersComplete, 1);
  EXPECT_EQ(callbacks.messageComplete, 0);
  EXPECT_EQ(callbacks.streamErrors, 0);
  EXPECT_EQ(callbacks.sessionErrors, 0);
  CHECK_NOTNULL(callbacks.msg.get());
  EXPECT_EQ(callbacks.msg->getHeaders().getNumberOfValues(kMultiValued),
            kNumValues);
}
开发者ID:191919,项目名称:proxygen,代码行数:30,代码来源:SPDYCodecTest.cpp

示例3: doEmptyHeaderValueTest

void doEmptyHeaderValueTest(Codec1& ingressCodec, Codec2& egressCodec) {
  uint8_t version = ingressCodec.getVersion();
  bool emptyAllowed = version != 2;
  FakeHTTPCodecCallback callbacks;
  ingressCodec.setCallback(&callbacks);
  HTTPMessage toSend;
  toSend.setMethod("GET");
  toSend.setURL("http://www.foo.com");
  auto& headers = toSend.getHeaders();
  headers.set("Host", "www.foo.com");
  headers.set("Pragma", "");
  headers.set("X-Test1", "yup");
  HTTPHeaderSize size;
  auto toParse = getSynStream(egressCodec, 1, toSend, 0, false, &size);
  ingressCodec.onIngress(*toParse);

  EXPECT_EQ(callbacks.sessionErrors, 0);
  EXPECT_EQ(callbacks.streamErrors, 0);
  ASSERT_NE(callbacks.msg.get(), nullptr);
  const auto& parsed = callbacks.msg->getHeaders();
  EXPECT_EQ(parsed.exists("Pragma"), emptyAllowed);
  EXPECT_EQ(parsed.exists("pragma"), emptyAllowed);
  EXPECT_EQ(parsed.getSingleOrEmpty("X-Test1"), "yup");
  // All codecs add the accept-encoding header
  EXPECT_EQ(parsed.exists("accept-encoding"), true);
  // SPDY/2 subtracts the Host header, but it should infer it from the host:port
  // portion of the requested url and present it in the headers
  EXPECT_EQ(parsed.exists("host"), true);
  EXPECT_EQ(callbacks.msg->getURL(), "http://www.foo.com");
  EXPECT_EQ(parsed.size(), emptyAllowed ? 4 : 3);
  EXPECT_TRUE(size.uncompressed > 0);
  EXPECT_TRUE(size.compressed > 0);
}
开发者ID:191919,项目名称:proxygen,代码行数:33,代码来源:SPDYCodecTest.cpp

示例4: getSynStream

unique_ptr<folly::IOBuf> getSynStream(Codec& egressCodec,
                                      uint32_t streamID) {
  HTTPMessage msg;
  msg.setMethod("GET");
  msg.getHeaders().set("HOST", "www.foo.com");
  msg.setURL("https://www.foo.com");
  return getSynStream(egressCodec, streamID, msg);
}
开发者ID:191919,项目名称:proxygen,代码行数:8,代码来源:SPDYCodecTest.cpp

示例5: 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;
}
开发者ID:SocialExplorerFork,项目名称:proxygen,代码行数:8,代码来源:TestUtils.cpp

示例6: 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;
}
开发者ID:lllhhhqqq,项目名称:proxygen,代码行数:9,代码来源:TestUtils.cpp

示例7: 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;
}
开发者ID:SocialExplorerFork,项目名称:proxygen,代码行数:10,代码来源:TestUtils.cpp

示例8: 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;
}
开发者ID:SocialExplorerFork,项目名称:proxygen,代码行数:10,代码来源:TestUtils.cpp

示例9: getUpgradeRequest

HTTPMessage getUpgradeRequest(const std::string& upgradeHeader,
                              HTTPMethod method, uint32_t bodyLen) {
  HTTPMessage req = getGetRequest();
  req.setMethod(method);
  req.getHeaders().set(HTTP_HEADER_UPGRADE, upgradeHeader);
  if (bodyLen > 0) {
    req.getHeaders().set(HTTP_HEADER_CONTENT_LENGTH,
                         folly::to<std::string>(bodyLen));
  }
  return req;
}
开发者ID:SocialExplorerFork,项目名称:proxygen,代码行数:11,代码来源:TestUtils.cpp

示例10: 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;
}
开发者ID:SocialExplorerFork,项目名称:proxygen,代码行数:12,代码来源:TestUtils.cpp

示例11: upstream

TEST_P(ConnectionHeaderTest, TestConnectionHeaders) {
  HTTP1xCodec upstream(TransportDirection::UPSTREAM);
  HTTP1xCodec downstream(TransportDirection::DOWNSTREAM);
  HTTP1xCodecCallback callbacks;
  downstream.setCallback(&callbacks);
  HTTPMessage req;
  req.setMethod(HTTPMethod::GET);
  req.setURL("/");
  auto val = GetParam();
  for (auto header: val.first) {
    req.getHeaders().add(HTTP_HEADER_CONNECTION, header);
  }
  folly::IOBufQueue writeBuf(folly::IOBufQueue::cacheChainLength());
  upstream.generateHeader(writeBuf, upstream.createStream(), req);
  downstream.onIngress(*writeBuf.front());
  EXPECT_EQ(callbacks.headersComplete, 1);
  auto& headers = callbacks.msg_->getHeaders();
  EXPECT_EQ(headers.getSingleOrEmpty(HTTP_HEADER_CONNECTION),
            val.second);
}
开发者ID:BeeswaxIO,项目名称:proxygen,代码行数:20,代码来源:HTTP1xCodecTest.cpp

示例12: 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);
}
开发者ID:BeeswaxIO,项目名称:proxygen,代码行数:20,代码来源:HTTP1xCodecTest.cpp


注:本文中的HTTPMessage::setMethod方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。