Use std::unordered_map<> in wxHTTP directly
Replace wxStringToStringHashMap with std::unordered_map<>, although still use (private) typedefs for the two different maps storing the cookies and the headers respectively for clarity. Also use a range for loop for iterating over the headers. Include wx/wxcrt.h from http.cpp explicitly because wxAtoi(), declared there, is used in this file, but it was previously only included indirectly via wx/hashmap.h.
This commit is contained in:
parent
492c1dd7c7
commit
a3be5fd165
2 changed files with 14 additions and 10 deletions
|
|
@ -14,10 +14,11 @@
|
|||
|
||||
#if wxUSE_PROTOCOL_HTTP
|
||||
|
||||
#include "wx/hashmap.h"
|
||||
#include "wx/protocol/protocol.h"
|
||||
#include "wx/buffer.h"
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
class WXDLLIMPEXP_NET wxHTTP : public wxProtocol
|
||||
{
|
||||
public:
|
||||
|
|
@ -51,10 +52,13 @@ public:
|
|||
wxDEPRECATED(void SetPostBuffer(const wxString& post_buf));
|
||||
|
||||
protected:
|
||||
typedef wxStringToStringHashMap::iterator wxHeaderIterator;
|
||||
typedef wxStringToStringHashMap::const_iterator wxHeaderConstIterator;
|
||||
typedef wxStringToStringHashMap::iterator wxCookieIterator;
|
||||
typedef wxStringToStringHashMap::const_iterator wxCookieConstIterator;
|
||||
using wxHeadersMap = std::unordered_map<wxString, wxString>;
|
||||
typedef wxHeadersMap::iterator wxHeaderIterator;
|
||||
typedef wxHeadersMap::const_iterator wxHeaderConstIterator;
|
||||
|
||||
using wxCookiesMap = std::unordered_map<wxString, wxString>;
|
||||
typedef wxCookiesMap::iterator wxCookieIterator;
|
||||
typedef wxCookiesMap::const_iterator wxCookieConstIterator;
|
||||
|
||||
bool BuildRequest(const wxString& path, const wxString& method);
|
||||
void SendHeaders();
|
||||
|
|
@ -75,9 +79,9 @@ protected:
|
|||
// internal variables:
|
||||
|
||||
wxString m_method;
|
||||
wxStringToStringHashMap m_cookies;
|
||||
wxCookiesMap m_cookies;
|
||||
|
||||
wxStringToStringHashMap m_headers;
|
||||
wxHeadersMap m_headers;
|
||||
bool m_read,
|
||||
m_proxy_mode;
|
||||
wxSockAddress *m_addr;
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@
|
|||
#include "wx/protocol/http.h"
|
||||
#include "wx/sckstrm.h"
|
||||
#include "wx/thread.h"
|
||||
#include "wx/wxcrt.h"
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
|
@ -227,12 +228,11 @@ wxHTTP::SetPostText(const wxString& contentType,
|
|||
|
||||
void wxHTTP::SendHeaders()
|
||||
{
|
||||
typedef wxStringToStringHashMap::iterator iterator;
|
||||
wxString buf;
|
||||
|
||||
for (iterator it = m_headers.begin(), en = m_headers.end(); it != en; ++it )
|
||||
for ( const auto& kv : m_headers )
|
||||
{
|
||||
buf.Printf(wxT("%s: %s\r\n"), it->first.c_str(), it->second.c_str());
|
||||
buf.Printf("%s: %s\r\n", kv.first, kv.second);
|
||||
|
||||
const wxWX2MBbuf cbuf = buf.mb_str();
|
||||
Write(cbuf, strlen(cbuf));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue