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


C++ HTTPMessage类代码示例

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


在下文中一共展示了HTTPMessage类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: TEST_F

TEST_F(HTTP2CodecTest, Chrome16kb) {
  HTTPMessage req = getGetRequest();
  string bigval(8691, '!');
  bigval.append(8691, ' ');
  req.getHeaders().add("x-headr", bigval);
  req.getHeaders().add("user-agent", agent2);
  upstreamCodec_.generateHeader(output_, 1, req, 0);
  upstreamCodec_.generateRstStream(output_, 1, ErrorCode::PROTOCOL_ERROR);

  parse();
  callbacks_.expectMessage(false, -1, "/");
  const auto& headers = callbacks_.msg->getHeaders();
  EXPECT_EQ(bigval, headers.getSingleOrEmpty("x-headr"));
  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);
  EXPECT_EQ(callbacks_.aborts, 1);
  EXPECT_EQ(callbacks_.lastErrorCode, ErrorCode::NO_ERROR);

  upstreamCodec_.generateSettingsAck(output_);
  parse();
  EXPECT_EQ(callbacks_.settingsAcks, 1);
}
开发者ID:KitJacky,项目名称:proxygen,代码行数:25,代码来源:HTTP2CodecTest.cpp

示例2: TEST

// 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:Neurochrom,项目名称:proxygen,代码行数:30,代码来源:SPDYCodecTest.cpp

示例3: TEST_P

TEST_P(ChromeHTTP2Test, ChromeContinuationSecondStream) {
  HPACKCodec09 headerCodec(TransportDirection::UPSTREAM);
  HTTPMessage req = getGetRequest();
  string agent = GetParam();
  req.getHeaders().add("user-agent", agent);
  generateHeaderChrome(headerCodec, output_, 1, req, 0, false, nullptr,
                       false);
  string bigval(1004, '!');
  bigval.append(1004, ' ');
  req.getHeaders().add("x-headerx", bigval);
  generateHeaderChrome(headerCodec, output_, 3, req, 0, false, nullptr,
                       agent.find("Chrome/43") == string::npos);

  parse();
  const auto& headers = callbacks_.msg->getHeaders();
  EXPECT_EQ(agent, headers.getSingleOrEmpty("user-agent"));
  EXPECT_EQ(bigval, headers.getSingleOrEmpty("x-headerx"));
  EXPECT_EQ(callbacks_.messageBegin, 2);
  EXPECT_EQ(callbacks_.headersComplete, 2);
  EXPECT_EQ(callbacks_.messageComplete, 0);
  EXPECT_EQ(callbacks_.streamErrors, 0);
  EXPECT_EQ(callbacks_.sessionErrors, 0);

  upstreamCodec_.generateSettingsAck(output_);
  parse();
  EXPECT_EQ(callbacks_.settingsAcks, 1);
}
开发者ID:KitJacky,项目名称:proxygen,代码行数:27,代码来源:HTTP2CodecTest.cpp

示例4: TEST_F

TEST_F(EchoHandlerFixture, ReplaysBodyProperly) {
  EXPECT_CALL(stats, recordRequest()).WillOnce(Return());
  EXPECT_CALL(stats, getRequestCount()).WillOnce(Return(5));

  HTTPMessage response;
  folly::fbstring body;

  EXPECT_CALL(*responseHandler, sendHeaders(_)).WillOnce(
      DoAll(SaveArg<0>(&response), Return()));

  EXPECT_CALL(*responseHandler, sendBody(_)).WillRepeatedly(
      DoAll(
          Invoke([&] (std::shared_ptr<folly::IOBuf> b) {
            body += b->moveToFbString();
          }),
          Return()));

  EXPECT_CALL(*responseHandler, sendEOM()).WillOnce(Return());

  // Since we know we dont touch request, its ok to pass `nullptr` here.
  handler->onRequest(nullptr);
  handler->onBody(folly::IOBuf::copyBuffer("part1"));
  handler->onBody(folly::IOBuf::copyBuffer("part2"));
  handler->onEOM();
  handler->requestComplete();

  EXPECT_EQ("5", response.getHeaders().getSingleOrEmpty("Request-Number"));
  EXPECT_EQ(200, response.getStatusCode());
  EXPECT_EQ("part1part2", body);
}
开发者ID:191919,项目名称:proxygen,代码行数:30,代码来源:EchoHandlerTest.cpp

示例5: TEST_F

TEST_F(HTTP2CodecTest, SettingsTableSize) {
  auto settings = upstreamCodec_.getEgressSettings();
  settings->setSetting(SettingsId::HEADER_TABLE_SIZE, 8192);
  upstreamCodec_.generateSettings(output_);

  parse();
  EXPECT_EQ(callbacks_.settings, 1);
  EXPECT_EQ(callbacks_.streamErrors, 0);
  EXPECT_EQ(callbacks_.sessionErrors, 0);

  callbacks_.reset();

  HTTPMessage resp;
  resp.setStatusCode(200);
  resp.setStatusMessage("nifty-nice");
  resp.getHeaders().add("content-type", "x-coolio");
  output_.move();
  downstreamCodec_.generateConnectionPreface(output_);
  downstreamCodec_.generateHeader(output_, 1, resp, 0);

  parseUpstream();
  callbacks_.expectMessage(false, 1, 200);
  const auto& headers = callbacks_.msg->getHeaders();
  EXPECT_EQ("x-coolio", headers.getSingleOrEmpty("content-type"));
}
开发者ID:ashwinmurthy,项目名称:proxygen,代码行数:25,代码来源:HTTP2CodecTest.cpp

示例6: sendHeadersWithOptionalEOM

void HTTPTransaction::sendHeadersWithOptionalEOM(
    const HTTPMessage& headers,
    bool eom) {
  CHECK(HTTPTransactionEgressSM::transit(
          egressState_, HTTPTransactionEgressSM::Event::sendHeaders));
  DCHECK(!isEgressComplete());
  if (isDownstream() && !isPushed()) {
    lastResponseStatus_ = headers.getStatusCode();
  }
  if (headers.isRequest()) {
    headRequest_ = (headers.getMethod() == HTTPMethod::HEAD);
  }
  HTTPHeaderSize size;
  transport_.sendHeaders(this, headers, &size, eom);
  if (transportCallback_) {
    transportCallback_->headerBytesGenerated(size);
  }
  if (eom) {
    CHECK(HTTPTransactionEgressSM::transit(
          egressState_, HTTPTransactionEgressSM::Event::sendEOM));
    // trailers are supported in this case:
    // trailers are for chunked encoding-transfer of a body
    if (transportCallback_) {
      transportCallback_->bodyBytesGenerated(0);
    }
    CHECK(HTTPTransactionEgressSM::transit(
          egressState_, HTTPTransactionEgressSM::Event::eomFlushed));
  }
  flushWindowUpdate();
}
开发者ID:abhiguru,项目名称:proxygen,代码行数:30,代码来源:HTTPTransaction.cpp

示例7: HTTPMessage

/**

    Process HTTP response message from cimserver

    @param   httpResponse        Array<char> reply from cimserver

    @param   ostream             the ostream to which output should be written

    @param   estream             the ostream to which errors should be written

    @return  true  = wait for data from challenge response
    @return  false = client response has been received

 */
void WbemExecCommand::_handleResponse( Array<char>           responseMessage,
                                          ostream&           oStream,
                                          ostream&           eStream
                                       )
{
    String                       startLine;
    Array<HTTPHeader>            headers;
    Uint32                       contentLength;
    Uint32                       contentOffset       = 0;
    HTTPMessage*                 httpMessage;
    Boolean                      needsAuthentication = false;

    httpMessage = new HTTPMessage( responseMessage, 0 );
    httpMessage->parse( startLine, headers, contentLength );
    if( contentLength > 0 )
      {
    contentOffset = responseMessage.size() - contentLength;
      }
    else
      {
        contentOffset = responseMessage.size();
      }

    String httpVersion;
    Uint32 statusCode;
    String reasonPhrase;

    Boolean parsableMessage = HTTPMessage::parseStatusLine(
        startLine, httpVersion, statusCode, reasonPhrase);
    if (!parsableMessage || (statusCode != HTTP_STATUSCODE_OK))
      {

    // Received an HTTP error response
    // Output the HTTP error message and exit
    for (Uint32 i = 0; i < contentOffset; i++)
      {
        oStream << responseMessage[i];
      }
    oStream.flush();
    if( contentLength > 0 )
      {
        _printContent( oStream, responseMessage, contentOffset );
      }
    exit( 1 );
      }

    //
    // Received a valid HTTP response from the server.
    //
    if (_debugOutput2)
      {
        for (Uint32 i = 0; i < contentOffset; i++)
          {
                oStream << responseMessage[i];
          }
        oStream.flush();
      }
    _printContent( oStream, responseMessage, contentOffset );
}
开发者ID:ncultra,项目名称:Pegasus-2.5,代码行数:73,代码来源:WbemExecCommand.cpp

示例8: 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

示例9: TEST

TEST(HTTPMessage, TestParseCookiesSimple) {
  HTTPMessage msg;

  msg.getHeaders().add("Cookie", "id=1256679245; data=0:1234567");
  EXPECT_EQ(msg.getCookie("id"), "1256679245");
  EXPECT_EQ(msg.getCookie("data"), "0:1234567");
  EXPECT_EQ(msg.getCookie("mising"), "");
}
开发者ID:abhiguru,项目名称:proxygen,代码行数:8,代码来源:HTTPMessageTest.cpp

示例10: 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

示例11: getResponse

HTTPMessage getResponse(uint32_t code, uint32_t bodyLen) {
  HTTPMessage resp;
  resp.setStatusCode(code);
  if (bodyLen > 0) {
    resp.getHeaders().set(HTTP_HEADER_CONTENT_LENGTH,
                          folly::to<string>(bodyLen));
  }
  return resp;
}
开发者ID:SocialExplorerFork,项目名称:proxygen,代码行数:9,代码来源:TestUtils.cpp

示例12: 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

示例13: 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

示例14: testPathAndQuery

void testPathAndQuery(const string& url,
                      const string& expectedPath,
                      const string& expectedQuery) {
  HTTPMessage msg;
  msg.setURL(url);

  EXPECT_EQ(msg.getURL(), url);
  EXPECT_EQ(msg.getPath(), expectedPath);
  EXPECT_EQ(msg.getQueryString(), expectedQuery);
}
开发者ID:abhiguru,项目名称:proxygen,代码行数:10,代码来源:HTTPMessageTest.cpp

示例15: 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


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