Applied modified #10655 (Added Cookie (receive) support to wxHTTP)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@62160 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
b0a9bfc8b8
commit
906cb3f119
@ -398,6 +398,7 @@ All:
|
||||
- Added wxAny class; a modern, backwards-incompatible replacement for
|
||||
wxVariant.
|
||||
- wxDateTime timezone functions now dynamic (no caching).
|
||||
- Added wxHttp::GetCookie and wxHttp::HasCookies (dodge).
|
||||
|
||||
All (GUI):
|
||||
|
||||
|
@ -39,6 +39,10 @@ public:
|
||||
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
|
||||
{
|
||||
@ -49,6 +53,8 @@ protected:
|
||||
|
||||
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();
|
||||
@ -59,13 +65,17 @@ protected:
|
||||
// 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;
|
||||
|
@ -92,5 +92,17 @@ public:
|
||||
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;
|
||||
};
|
||||
|
||||
|
@ -66,6 +66,11 @@ void wxHTTP::ClearHeaders()
|
||||
m_headers.clear();
|
||||
}
|
||||
|
||||
void wxHTTP::ClearCookies()
|
||||
{
|
||||
m_cookies.clear();
|
||||
}
|
||||
|
||||
wxString wxHTTP::GetContentType() const
|
||||
{
|
||||
return GetHeader(wxT("Content-Type"));
|
||||
@ -100,6 +105,30 @@ wxHTTP::wxHeaderConstIterator wxHTTP::FindHeader(const wxString& header) const
|
||||
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) {
|
||||
@ -121,6 +150,13 @@ wxString wxHTTP::GetHeader(const wxString& header) const
|
||||
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+/";
|
||||
@ -178,6 +214,7 @@ bool wxHTTP::ParseHeaders()
|
||||
wxStringTokenizer tokenzr;
|
||||
|
||||
ClearHeaders();
|
||||
ClearCookies();
|
||||
m_read = true;
|
||||
|
||||
for ( ;; )
|
||||
@ -190,7 +227,19 @@ bool wxHTTP::ParseHeaders()
|
||||
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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user