Skip to content

Commit

Permalink
Merge branch 'master' of github.com:avp-avp/libs
Browse files Browse the repository at this point in the history
  • Loading branch information
avp-avp committed Feb 26, 2017
2 parents 0ef7df3 + 0225b2e commit 8d0a024
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 11 deletions.
44 changes: 34 additions & 10 deletions libcomm/WebClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,18 @@ string CWebClient::GetHeaders()
if (m_ContentType!=None)
header += "Content-Type: "+GetContentType()+"\n";

string cookies;
for_each(string_map, m_Cookie, cookie)
{
if (cookies.length())
cookies += "; ";

cookies += cookie->first + "=" + cookie->second;
}

if (cookies.length())
header += "Cookie: " + cookies + "\n";

return header;
}

Expand All @@ -93,7 +105,6 @@ void CWebClient::OnRecieve(CConnection* Conn)
char Buffer[4096];
size_t size = sizeof(Buffer) - 1;


try
{
Conn->Recv(Buffer, size, false);
Expand Down Expand Up @@ -152,17 +163,31 @@ void CWebClient::OnRecieve(CConnection* Conn)
}
else
{
string_vector v;
SplitString(line, ':', v);
if (v.size() != 2)
continue; // bad line?
int pos = line.find(':');
if (pos == line.npos)
continue;

string key = v[0];
string value = v[1];
if (value.length()>0 && value[0] == ' ')
string key = line.substr(0, pos);
string value = line.substr(pos + 1);
if (value.length() > 0 && value[0] == ' ')
value = value.substr(1);

m_Headers[key] = value;
if (key == "Set-Cookie")
{
//SplitValues
pos = value.find('=');
if (pos == value.npos)
continue;
string cookieKey = value.substr(0, pos);
string cookieValue = value.substr(pos + 1);
pos = cookieValue.find(";");
if (pos != cookieValue.npos)
cookieValue = cookieValue.substr(0, pos);

m_Cookie[cookieKey] = cookieValue;
}
else
m_Headers[key] = value;
}
}
}
Expand All @@ -175,7 +200,6 @@ void CWebClient::ClearResponse(){
m_ContentType = None;
}


bool CWebClient::isTimeout(){
return m_RequestTime>0 && m_RequestTime+m_Timeout<time(NULL);
}
3 changes: 2 additions & 1 deletion libcomm/WebClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,14 @@ class LIBCOMM_API CWebClient
RequestType m_RequestType;
string m_Response;
bool m_HaveResponse;
string_map m_Headers;
string_map m_Headers, m_Cookie;
CIPConnection *m_Connection;
int m_ResponseCode;
time_t m_RequestTime;
int m_Timeout;



public:
CWebClient(CSupervisor *Supervisor, int Timeout=10);
~CWebClient();
Expand Down

0 comments on commit 8d0a024

Please sign in to comment.