mirror of https://github.com/aria2/aria2
Supported multi-line HTTP header field value.
See http://tools.ietf.org/html/rfc2616#section-4.2pull/1/head
parent
7a857e1913
commit
1d71626bea
|
@ -193,15 +193,26 @@ void HttpHeader::setRequestPath(const std::string& requestPath)
|
||||||
void HttpHeader::fill(std::istream& in)
|
void HttpHeader::fill(std::istream& in)
|
||||||
{
|
{
|
||||||
std::string line;
|
std::string line;
|
||||||
while(std::getline(in, line)) {
|
std::getline(in, line);
|
||||||
|
while(in) {
|
||||||
line = util::strip(line);
|
line = util::strip(line);
|
||||||
if(line.empty()) {
|
if(line.empty()) {
|
||||||
continue;
|
std::getline(in, line);
|
||||||
}
|
} else {
|
||||||
std::pair<std::string, std::string> hp;
|
std::pair<std::string, std::string> hp;
|
||||||
util::divide(hp, line, ':');
|
util::divide(hp, line, ':');
|
||||||
|
while(std::getline(in, line)) {
|
||||||
|
if(!line.empty() && (line[0] == ' ' || line[0] == '\t')) {
|
||||||
|
line = util::strip(line);
|
||||||
|
hp.second += " ";
|
||||||
|
hp.second += line;
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
put(hp.first, hp.second);
|
put(hp.first, hp.second);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void HttpHeader::clearField()
|
void HttpHeader::clearField()
|
||||||
|
|
|
@ -1,7 +1,11 @@
|
||||||
#include "HttpHeader.h"
|
#include "HttpHeader.h"
|
||||||
#include "Range.h"
|
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
#include <cppunit/extensions/HelperMacros.h>
|
#include <cppunit/extensions/HelperMacros.h>
|
||||||
|
|
||||||
|
#include "Range.h"
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
class HttpHeaderTest:public CppUnit::TestFixture {
|
class HttpHeaderTest:public CppUnit::TestFixture {
|
||||||
|
@ -10,12 +14,14 @@ class HttpHeaderTest:public CppUnit::TestFixture {
|
||||||
CPPUNIT_TEST(testGetRange);
|
CPPUNIT_TEST(testGetRange);
|
||||||
CPPUNIT_TEST(testGet);
|
CPPUNIT_TEST(testGet);
|
||||||
CPPUNIT_TEST(testClearField);
|
CPPUNIT_TEST(testClearField);
|
||||||
|
CPPUNIT_TEST(testFill);
|
||||||
CPPUNIT_TEST_SUITE_END();
|
CPPUNIT_TEST_SUITE_END();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void testGetRange();
|
void testGetRange();
|
||||||
void testGet();
|
void testGet();
|
||||||
void testClearField();
|
void testClearField();
|
||||||
|
void testFill();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -96,4 +102,28 @@ void HttpHeaderTest::testClearField()
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string(HttpHeader::HTTP_1_1), h.getVersion());
|
CPPUNIT_ASSERT_EQUAL(std::string(HttpHeader::HTTP_1_1), h.getVersion());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void HttpHeaderTest::testFill()
|
||||||
|
{
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << "Host: aria2.sourceforge.net\r\n"
|
||||||
|
<< "Connection: close \r\n" // trailing white space
|
||||||
|
<< "Multi-Line: text1\r\n"
|
||||||
|
<< " text2\r\n"
|
||||||
|
<< " text3\r\n"
|
||||||
|
<< "Duplicate: foo\r\n"
|
||||||
|
<< "Duplicate: bar\r\n";
|
||||||
|
HttpHeader h;
|
||||||
|
h.fill(ss);
|
||||||
|
CPPUNIT_ASSERT_EQUAL(std::string("aria2.sourceforge.net"),
|
||||||
|
h.getFirst("Host"));
|
||||||
|
CPPUNIT_ASSERT_EQUAL(std::string("close"),
|
||||||
|
h.getFirst("Connection"));
|
||||||
|
CPPUNIT_ASSERT_EQUAL(std::string("text1 text2 text3"),
|
||||||
|
h.getFirst("Multi-Line"));
|
||||||
|
CPPUNIT_ASSERT_EQUAL(std::string("foo"),
|
||||||
|
h.get("Duplicate")[0]);
|
||||||
|
CPPUNIT_ASSERT_EQUAL(std::string("bar"),
|
||||||
|
h.get("Duplicate")[1]);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
Loading…
Reference in New Issue