本文整理汇总了C++中HTTPMessage::setURL方法的典型用法代码示例。如果您正苦于以下问题:C++ HTTPMessage::setURL方法的具体用法?C++ HTTPMessage::setURL怎么用?C++ HTTPMessage::setURL使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HTTPMessage
的用法示例。
在下文中一共展示了HTTPMessage::setURL方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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);
}
示例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);
}
示例3: 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;
}
示例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);
}
示例5: 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);
}
示例6: testRemoveQueryParam
void testRemoveQueryParam(const string& url,
const string& queryParam,
const string& expectedUrl,
const string& expectedQuery) {
HTTPMessage msg;
msg.setURL(url);
bool expectedChange = (url != expectedUrl);
EXPECT_EQ(msg.removeQueryParam(queryParam), expectedChange);
EXPECT_EQ(msg.getURL(), expectedUrl);
EXPECT_EQ(msg.getQueryString(), expectedQuery);
}
示例7: 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;
}
示例8: sort
TEST(HTTPMessage, TestParseQueryParamsComplex) {
HTTPMessage msg;
std::vector<std::vector<std::string>> input = {
{"", "", ""},
{"key_and_equal_but_no_value", "=", ""},
{"only_key", "", ""},
{"key_and_value", "=", "value"},
{"key_and_value_2", "=", "value2"},
{"key_and_value_3", "=", "value3"}
};
for (int i = 0; i < (1 << input.size()); ++i) {
std::vector<std::vector<std::string>> sub;
for (size_t j = 0; j < input.size(); ++j) {
if ((i & (1 << j))) {
sub.push_back(input[j]);
}
}
sort(sub.begin(), sub.end());
do {
bool first = true;
std::string url = "/test?";
for (const auto& val: sub) {
if (first) {
first = false;
} else {
url += "&";
}
url += val[0] + val[1] + val[2];
}
msg.setURL(url);
for (const auto& val: sub) {
if (val[0].empty()) {
continue;
}
EXPECT_EQ(val[2], msg.getQueryParam(val[0]));
}
} while (next_permutation(sub.begin(), sub.end()));
}
}
示例9: clear
TEST(HTTPMessage, TestParseQueryParamsSimple) {
HTTPMessage msg;
string url = "/test?seq=123456&userid=1256679245&dup=1&dup=2&helloWorld"
"&second=was+it+clear+%28already%29%3F";
msg.setURL(url);
EXPECT_EQ(msg.getQueryParam("seq"), "123456");
EXPECT_EQ(msg.getQueryParam("userid"), "1256679245");
EXPECT_EQ(msg.getQueryParam("dup"), "2");
EXPECT_EQ(msg.getQueryParam("helloWorld"), "");
EXPECT_EQ(msg.getIntQueryParam("dup", 5), 2);
EXPECT_EQ(msg.getIntQueryParam("abc", 5), 5);
EXPECT_EQ(msg.getDecodedQueryParam("second"), "was it clear (already)?");
EXPECT_EQ(msg.getDecodedQueryParam("seq"), "123456");
EXPECT_EQ(msg.hasQueryParam("seq"), true);
EXPECT_EQ(msg.hasQueryParam("seq1"), false);
EXPECT_EQ(msg.getIntQueryParam("dup"), 2);
EXPECT_ANY_THROW(msg.getIntQueryParam("abc"));
EXPECT_ANY_THROW(msg.getIntQueryParam("second"));
}
示例10: 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);
}
示例11: 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);
}