本文整理汇总了C++中HttpMessage::getFirstHeaderLinePart方法的典型用法代码示例。如果您正苦于以下问题:C++ HttpMessage::getFirstHeaderLinePart方法的具体用法?C++ HttpMessage::getFirstHeaderLinePart怎么用?C++ HttpMessage::getFirstHeaderLinePart使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HttpMessage
的用法示例。
在下文中一共展示了HttpMessage::getFirstHeaderLinePart方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: testMessage
/**
* Test header, message, body, message contructor
*/
void testMessage()
{
// TODO break this up into several tests. Too intertwined
const char* name = "Content-Type";
const char* value = "text/plain";
const char* httpTopLine = "GET /index.html HTTP/1.0";
const char* valueRef = NULL;
const char* n2 = "yyy";
const char* v2 = "yyy-value";
const char* v2a = "yyy-value2";
UtlString messageBytes;
UtlString messageBytes2;
ssize_t messageLen = 0;
ssize_t messageLen2 = 0;
const char* body = "<HTML>\n<H3>Hello\n<BR>\n</HTML>\n";
const HttpBody *bodyRef;
ssize_t bodyLength = 0;
UtlString headerLinePart;
HttpMessage *msg;
HttpMessage *msg2;
msg = new HttpMessage();
// H E A D E R
int fieldCount = msg->getCountHeaderFields();
CPPUNIT_ASSERT_EQUAL_MESSAGE("field count should be zero",
0, fieldCount);
msg->addHeaderField(name, value);
fieldCount = msg->getCountHeaderFields();
CPPUNIT_ASSERT_EQUAL_MESSAGE("field count should be zero", 1,
fieldCount);
valueRef = msg->getHeaderValue(0);
CPPUNIT_ASSERT_MESSAGE("NULL field value", valueRef != NULL);
ASSERT_STR_EQUAL_MESSAGE("incorrect field value", value,
valueRef);
msg->setFirstHeaderLine(httpTopLine);
valueRef = msg->getFirstHeaderLine();
ASSERT_STR_EQUAL_MESSAGE("incorrect top header line value",
valueRef, httpTopLine);
valueRef = msg->getHeaderValue(0, name);
CPPUNIT_ASSERT_MESSAGE("NULL field value", valueRef != NULL);
ASSERT_STR_EQUAL_MESSAGE("incorrect field value", value,
valueRef);
msg->addHeaderField(n2, v2);
fieldCount = msg->getCountHeaderFields();
CPPUNIT_ASSERT_EQUAL_MESSAGE("field count should be 2", 2,
fieldCount);
valueRef = msg->getHeaderValue(0, n2);
CPPUNIT_ASSERT_MESSAGE("NULL field value", valueRef != NULL);
ASSERT_STR_EQUAL_MESSAGE("incorrect field value", v2,
valueRef);
msg->addHeaderField(n2, v2a);
fieldCount = msg->getCountHeaderFields();
CPPUNIT_ASSERT_EQUAL_MESSAGE("field count should be 3", 3,
fieldCount);
valueRef = msg->getHeaderValue(1, n2);
CPPUNIT_ASSERT_MESSAGE("NULL field value", valueRef != NULL);
ASSERT_STR_EQUAL_MESSAGE("incorrect field value", v2a,
valueRef);
// B O D Y
HttpBody *httpBody = new HttpBody(body, strlen(body));
msg->setBody(httpBody);
bodyRef = msg->getBody();
CPPUNIT_ASSERT_MESSAGE("bad body pointer", httpBody == bodyRef);
bodyRef->getBytes(&valueRef, &bodyLength);
CPPUNIT_ASSERT_MESSAGE("bad body pointer", valueRef != NULL);
CPPUNIT_ASSERT_EQUAL_MESSAGE("incorrect body len", (ssize_t)strlen(body),
bodyLength);
ASSERT_STR_EQUAL_MESSAGE("incorrect body value", body, valueRef);
const char* expectedLinePart[] = {
"GET", "/index.html", "HTTP/1.0"
};
size_t n = sizeof(expectedLinePart) / sizeof(expectedLinePart[0]);
for (size_t i = 0; i < n; i++)
{
msg->getFirstHeaderLinePart(i, &headerLinePart);
CPPUNIT_ASSERT_MESSAGE("NULL header line part pointer",
!headerLinePart.isNull());
ASSERT_STR_EQUAL_MESSAGE("incorrect hdr line", expectedLinePart[i],
headerLinePart.data());
headerLinePart.remove(0);
}
msg->getBytes(&messageBytes, &messageLen);
CPPUNIT_ASSERT_MESSAGE("NULL body pointer", !messageBytes.isNull());
//.........这里部分代码省略.........