Commit 43e1b4d5 authored by 's avatar

Fix Whitespace

parent 6b8cdfa3
......@@ -212,32 +212,32 @@ CookieJar::add(const Cookie& cookie) {
void
CookieJar::addFromRaw(const char *str, size_t len) {
RawStreamBuf<> buf(const_cast<char *>(str), len);
StreamCursor cursor(&buf);
while (!cursor.eof()) {
StreamCursor::Token nameToken(cursor);
if (!match_until('=', cursor))
throw std::runtime_error("Invalid cookie, missing value");
auto name = nameToken.text();
if (!cursor.advance(1))
throw std::runtime_error("Invalid cookie, missing value");
StreamCursor::Token valueToken(cursor);
match_until(';', cursor);
auto value = valueToken.text();
Cookie cookie(std::move(name), std::move(value));
add(cookie);
cursor.advance(1);
skip_whitespaces(cursor);
}
}
RawStreamBuf<> buf(const_cast<char *>(str), len);
StreamCursor cursor(&buf);
while (!cursor.eof()) {
StreamCursor::Token nameToken(cursor);
if (!match_until('=', cursor))
throw std::runtime_error("Invalid cookie, missing value");
auto name = nameToken.text();
if (!cursor.advance(1))
throw std::runtime_error("Invalid cookie, missing value");
StreamCursor::Token valueToken(cursor);
match_until(';', cursor);
auto value = valueToken.text();
Cookie cookie(std::move(name), std::move(value));
add(cookie);
cursor.advance(1);
skip_whitespaces(cursor);
}
}
Cookie
CookieJar::get(const std::string& name) const {
......
......@@ -294,7 +294,7 @@ namespace Private {
}
if (name == "Cookie") {
message->cookies_.addFromRaw(cursor.offset(start), cursor.diff(start));
message->cookies_.addFromRaw(cursor.offset(start), cursor.diff(start));
}
else if (Header::Registry::isRegistered(name)) {
......
......@@ -137,14 +137,14 @@ void addCookies(const char* str, std::function<void (const CookieJar&)> testFunc
TEST(cookie_test, cookiejar_test) {
addCookies("key1=value1", [](const CookieJar& jar) {
ASSERT_EQ(jar.get("key1").value, "value1");
ASSERT_EQ(jar.get("key1").value, "value1");
});
addCookies("key2=value2; key3=value3", [](const CookieJar& jar) {
ASSERT_EQ(jar.get("key2").value, "value2");
ASSERT_EQ(jar.get("key3").value, "value3");
ASSERT_EQ(jar.get("key2").value, "value2");
ASSERT_EQ(jar.get("key3").value, "value3");
});
CookieJar jar;
ASSERT_THROW(jar.addFromRaw("key4", strlen("key4")), std::runtime_error);
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment