void SetPostBuffer(const wxString& post_buf);
void SetProxyMode(bool on);
+ /* Cookies */
+ wxString GetCookie(const wxString& cookie) const;
+ bool HasCookies() const { return m_cookies.size() > 0; }
+
protected:
enum wxHTTP_Req
{
typedef wxStringToStringHashMap::iterator wxHeaderIterator;
typedef wxStringToStringHashMap::const_iterator wxHeaderConstIterator;
+ typedef wxStringToStringHashMap::iterator wxCookieIterator;
+ typedef wxStringToStringHashMap::const_iterator wxCookieConstIterator;
bool BuildRequest(const wxString& path, wxHTTP_Req req);
void SendHeaders();
// find the header in m_headers
wxHeaderIterator FindHeader(const wxString& header);
wxHeaderConstIterator FindHeader(const wxString& header) const;
+ wxCookieIterator FindCookie(const wxString& cookie);
+ wxCookieConstIterator FindCookie(const wxString& cookie) const;
// deletes the header value strings
void ClearHeaders();
-
+ void ClearCookies();
// internal variables:
+ wxStringToStringHashMap m_cookies;
+
wxStringToStringHashMap m_headers;
bool m_read,
m_proxy_mode;
This is a low level function and it assumes that you know what you are doing.
*/
void SetHeader(const wxString& header, const wxString& h_data);
+
+ /**
+ Returns the value of a cookie.
+ */
+
+ wxString GetCookie(const wxString& cookie) const;
+
+ /**
+ Returns @true if there were cookies.
+ */
+
+ bool HasCookies() const;
};
m_headers.clear();
}
+void wxHTTP::ClearCookies()
+{
+ m_cookies.clear();
+}
+
wxString wxHTTP::GetContentType() const
{
return GetHeader(wxT("Content-Type"));
return it;
}
+wxHTTP::wxCookieIterator wxHTTP::FindCookie(const wxString& cookie)
+{
+ wxCookieIterator it = m_cookies.begin();
+ for ( wxCookieIterator en = m_cookies.end(); it != en; ++it )
+ {
+ if ( cookie.CmpNoCase(it->first) == 0 )
+ break;
+ }
+
+ return it;
+}
+
+wxHTTP::wxCookieConstIterator wxHTTP::FindCookie(const wxString& cookie) const
+{
+ wxCookieConstIterator it = m_cookies.begin();
+ for ( wxCookieConstIterator en = m_cookies.end(); it != en; ++it )
+ {
+ if ( cookie.CmpNoCase(it->first) == 0 )
+ break;
+ }
+
+ return it;
+}
+
void wxHTTP::SetHeader(const wxString& header, const wxString& h_data)
{
if (m_read) {
return it == m_headers.end() ? wxGetEmptyString() : it->second;
}
+wxString wxHTTP::GetCookie(const wxString& cookie) const
+{
+ wxCookieConstIterator it = FindCookie(cookie);
+
+ return it == m_cookies.end() ? wxGetEmptyString() : it->second;
+}
+
wxString wxHTTP::GenerateAuthString(const wxString& user, const wxString& pass) const
{
static const char *base64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
wxStringTokenizer tokenzr;
ClearHeaders();
+ ClearCookies();
m_read = true;
for ( ;; )
break;
wxString left_str = line.BeforeFirst(':');
- m_headers[left_str] = line.AfterFirst(':').Strip(wxString::both);
+ if(!left_str.CmpNoCase("Set-Cookie"))
+ {
+ wxString cookieName = line.AfterFirst(':').Strip(wxString::both).BeforeFirst('=');
+ wxString cookieValue = line.AfterFirst(':').Strip(wxString::both).AfterFirst('=').BeforeFirst(';');
+ m_cookies[cookieName] = cookieValue;
+
+ // For compatibility
+ m_headers[left_str] = line.AfterFirst(':').Strip(wxString::both);
+ }
+ else
+ {
+ m_headers[left_str] = line.AfterFirst(':').Strip(wxString::both);
+ }
}
return true;
}