Opened 12 years ago
Closed 11 years ago
#10655 closed enhancement (fixed)
Added Cookie (receive) support to wxHTTP
Reported by: | dodge | Owned by: | |
---|---|---|---|
Priority: | normal | Milestone: | |
Component: | network | Version: | stable-latest |
Keywords: | wxHTTP cookies | Cc: | |
Blocked By: | Blocking: | ||
Patch: | yes |
Description
I implemented some support for cookies to wxHTTP.
The current wxHTTP can't handle cookies, at least not more than one.
Why? The wxHTTP::ParseHeader() function reads headers line by line and puts a key/value pair into (wxStringToStringHashMap)m_headers. That works fine for all header but not for Set-Cookie if there is more than 1 cookie. In that case only the last cookie gets saved im m_headers.
What i did was adding the option to call EnableCookies() telling the ParseHeader() function to not put Set-Cookie headers into the m_headers but instead saveing the cookie as name/value pair into m_cookies.
Cookies can be accessed with "wxString GetCookie(const wxString& cookie) const;" to check if there are cookies i added "bool HasCookies()". There is also an ClearCookies() function to remove all cookies :)
+ Functions:
public:
wxString GetCookie(const wxString& cookie) const;
bool HasCookies();
void EnableCookies(bool on = true);
void DisableCookies();
protected:
void ClearCookies();
wxCookieIterator FindCookie(const wxString& cookie);
wxCookieConstIterator FindCookie(const wxString& cookie) const;
+ Typedef:
typedef wxStringToStringHashMap::iterator wxCookieIterator;
typedef wxStringToStringHashMap::const_iterator wxCookieConstIterator;
+ Variable:
protected:
bool m_useCookies;
wxStringToStringHashMap m_cookies;
SVN Diff: http://rafb.net/p/1gOeeL57.html
Attachments (1)
Change History (6)
Changed 12 years ago by dodge
comment:1 Changed 12 years ago by dodge
Oh, i forgot to mention that this support is by default disabled to not break current code/software. It has to be enabled with EnableCookies().
comment:2 Changed 12 years ago by vadz
- Status changed from new to infoneeded_new
Thanks for the patch, this would be definitely a useful feature to have! However before applying it we really need to document the new functions, i.e. add their descriptions to interface/wx/http.h -- could you please do it?
Also, I don't see any problem with enabling this by default: there is no reason we can't store the cookie in m_cookies and m_headers (for compatibility). So IMO EnableCookies() is simply not needed at all.
Could you please update the patch to include the docs? TIA!
P.S. Please also let me know the name under which you'd like to be credited in docs/changes.txt.
comment:3 Changed 12 years ago by dodge
- Status changed from infoneeded_new to new
I dont have a interface/wx/http.h in my SVN :/
comment:4 Changed 12 years ago by vadz
- Status changed from new to infoneeded_new
Sorry, it's interface/wx/protocol/http.h.
comment:5 Changed 11 years ago by juliansmart
- Resolution set to fixed
- Status changed from infoneeded_new to closed
Thanks - applied with Vadim's suggestions to trunk (r62160).
.patch file for SVN Diff