Fix the "map/set iterators incompatible" bug.

cookies is only valid when AIHTTPReceivedHeaders::getValues return true.
This commit is contained in:
Aleric Inglewood
2013-01-12 04:24:14 +01:00
parent e56f14502e
commit 024c62aed4
2 changed files with 11 additions and 7 deletions

View File

@@ -370,7 +370,8 @@ void LLHTTPClient::ResponderBase::decode_raw_body(U32 status, std::string const&
std::string const& LLHTTPClient::ResponderBase::get_cookie(std::string const& key) std::string const& LLHTTPClient::ResponderBase::get_cookie(std::string const& key)
{ {
AIHTTPReceivedHeaders::range_type cookies; AIHTTPReceivedHeaders::range_type cookies;
mReceivedHeaders.getValues("set-cookie", cookies); if (mReceivedHeaders.getValues("set-cookie", cookies))
{
for (AIHTTPReceivedHeaders::iterator_type cookie = cookies.first; cookie != cookies.second; ++cookie) for (AIHTTPReceivedHeaders::iterator_type cookie = cookies.first; cookie != cookies.second; ++cookie)
{ {
if (key == cookie->second.substr(0, cookie->second.find('='))) if (key == cookie->second.substr(0, cookie->second.find('=')))
@@ -378,6 +379,7 @@ std::string const& LLHTTPClient::ResponderBase::get_cookie(std::string const& ke
return cookie->second; return cookie->second;
} }
} }
}
// Not found. // Not found.
static std::string empty_dummy; static std::string empty_dummy;
return empty_dummy; return empty_dummy;

View File

@@ -158,11 +158,13 @@ public:
// Erase all headers EXCEPT the cookies. // Erase all headers EXCEPT the cookies.
AIHTTPReceivedHeaders set_cookie_headers; AIHTTPReceivedHeaders set_cookie_headers;
AIHTTPReceivedHeaders::range_type cookies; AIHTTPReceivedHeaders::range_type cookies;
mReceivedHeaders.getValues("set-cookie", cookies); if (mReceivedHeaders.getValues("set-cookie", cookies))
{
for (AIHTTPReceivedHeaders::iterator_type cookie = cookies.first; cookie != cookies.second; ++cookie) for (AIHTTPReceivedHeaders::iterator_type cookie = cookies.first; cookie != cookies.second; ++cookie)
{ {
set_cookie_headers.addHeader(cookie->first, cookie->second); set_cookie_headers.addHeader(cookie->first, cookie->second);
} }
}
// Replace headers with just the cookie headers. // Replace headers with just the cookie headers.
mReceivedHeaders.swap(set_cookie_headers); mReceivedHeaders.swap(set_cookie_headers);
} }