Permalink
Browse files

http, bugfix: parallel request in HttpClient will crash when response…

… cookies.
  • Loading branch information...
xicilion committed Nov 10, 2017
1 parent 910b473 commit b82e545c1caaf84270d7a72b76a525d136c3e4df
Showing with 16 additions and 5 deletions.
  1. +1 −0 fibjs/include/HttpClient.h
  2. +15 −5 fibjs/src/http/HttpClient.cpp
@@ -63,6 +63,7 @@ class HttpClient : public HttpClient_base {
private:
obj_ptr<NArray> m_cookies;
exlib::spinlock m_lock_cookies;
int32_t m_timeout;
bool m_enableCookie;
bool m_autoRedirect;
@@ -161,9 +161,13 @@ result_t HttpClient::update_cookies(exlib::string url, NArray* cookies)
if (hr < 0)
return hr;
m_lock_cookies.lock();
cookies->get_length(length);
if (length == 0)
if (length == 0) {
m_lock_cookies.unlock();
return 0;
}
for (i = 0; i < length; i++) {
Variant v;
@@ -184,6 +188,8 @@ result_t HttpClient::update_cookies(exlib::string url, NArray* cookies)
if (update(hc) == 0)
m_cookies->append(hc);
}
m_lock_cookies.unlock();
return 0;
}
@@ -197,15 +203,18 @@ result_t HttpClient::get_cookie(exlib::string url, exlib::string& retVal)
exlib::string s2;
date_t now;
m_cookies->get_length(length);
if (length == 0)
return 0;
obj_ptr<Url> u = new Url();
hr = u->parse(url);
if (hr < 0)
return hr;
m_lock_cookies.lock();
m_cookies->get_length(length);
if (length == 0) {
m_lock_cookies.unlock();
return 0;
}
now.now();
for (i = 0; i < length; i++) {
@@ -239,6 +248,7 @@ result_t HttpClient::get_cookie(exlib::string url, exlib::string& retVal)
if (s.length() > 0)
retVal = s.substr(0, s.length() - 2);
m_lock_cookies.unlock();
return 0;
}

0 comments on commit b82e545

Please sign in to comment.