本文整理汇总了C++中HttpRequest::FormatRequest方法的典型用法代码示例。如果您正苦于以下问题:C++ HttpRequest::FormatRequest方法的具体用法?C++ HttpRequest::FormatRequest怎么用?C++ HttpRequest::FormatRequest使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HttpRequest
的用法示例。
在下文中一共展示了HttpRequest::FormatRequest方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: test_request
static void test_request()
{
static const struct {
int d_line;
std::string d_input;
std::string d_expected_output;
} DATA[] = {
// Check that inputs are normalized
// LINE // INPUT // EXP
{L_, "GET http://google.com/ HTTP/1.1\r\n\r\n" , "GET / HTTP/1.1\r\n"
"Host: google.com\r\n\r\n"},
{L_, "GET http://www.google.com/ HTTP/1.1\r\n\r\n", "GET / HTTP/1.1\r\n"
"Host: google.com\r\n\r\n"},
{L_, "GET www.google.com/ HTTP/1.1\r\n\r\n" , "GET / HTTP/1.1\r\n"
"Host: google.com\r\n\r\n"},
{L_, "GET google.com/ HTTP/1.1\r\n\r\n" , "GET / HTTP/1.1\r\n"
"Host: google.com\r\n\r\n"},
// Check a HEAD Request
// LINE // INPUT // EXP
{L_, "HEAD http://google.com/ HTTP/1.1\r\n\r\n" , "HEAD / HTTP/1.1\r\n"
"Host: google.com\r\n\r\n"},
// Check a request with a PATH
{L_, "GET http://cs.ucla.edu"
"/classes/fall13/cs111/news.html "
"HTTP/1.1\r\n\r\n" ,
"GET /classes/fall13/cs111/news.html HTTP/1.1\r\n"
"Host: cs.ucla.edu\r\n\r\n"},
// Check a request with more headers
{L_, "GET http://cs.ucla.edu"
"/classes/fall13/cs111/news.html "
"HTTP/1.1\r\n"
"Accept-Encoding: identity\r\n"
"If-Modified-Since: Sat, 15 Feb 2014 17:00:59 GMT\r\n\r\n",
"GET /classes/fall13/cs111/news.html HTTP/1.1\r\n"
"Host: cs.ucla.edu\r\n"
"Accept-Encoding: identity\r\n"
"If-Modified-Since: Sat, 15 Feb 2014 17:00:59 GMT\r\n\r\n"},
};
const size_t NUM_DATA = sizeof (DATA) / sizeof (*DATA);
for (size_t ti = 0; ti < NUM_DATA; ++ti) {
const int LINE = DATA[ti].d_line;
const char *INPUT = DATA[ti].d_input.c_str();
const size_t LEN_INPUT = DATA[ti].d_input.length();
const char *EXP_OUTPUT = DATA[ti].d_expected_output.c_str();
char *output = new char[LEN_INPUT];
if (veryVeryVerbose) { T_ P(LINE) };
HttpRequest req;
req.ParseRequest(INPUT, LEN_INPUT);
req.FormatRequest(output);
ASSERT(0 == strcmp(output, EXP_OUTPUT))
}
}