X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/71414756b2cb4d64ee167e61f3fa4854c4f2a85b..3ca1bf5add01419ba173f0567b060fdd9fd605f9:/src/common/http.cpp?ds=sidebyside diff --git a/src/common/http.cpp b/src/common/http.cpp index 4a59548bf3..0e7d3a3346 100644 --- a/src/common/http.cpp +++ b/src/common/http.cpp @@ -9,7 +9,7 @@ // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// -#ifdef __GNUG__ +#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) #pragma implementation "http.h" #endif @@ -44,6 +44,7 @@ wxHTTP::wxHTTP() m_read = FALSE; m_proxy_mode = FALSE; m_post_buf = wxEmptyString; + m_http_response = 0; SetNotify(wxSOCKET_LOST_FLAG); } @@ -70,13 +71,22 @@ void wxHTTP::SetProxyMode(bool on) m_proxy_mode = on; } -wxHTTP::wxHeaderIterator wxHTTP::FindHeader(const wxString& header) const +wxHTTP::wxHeaderIterator wxHTTP::FindHeader(const wxString& header) { - // we can't convert between const_iterator to iterator otherwise... - wxStringToStringHashMap& headers = (wxStringToStringHashMap&)m_headers; + wxHeaderIterator it = m_headers.begin(); + for ( wxHeaderIterator en = m_headers.end(); it != en; ++it ) + { + if ( wxStricmp(it->first, header) == 0 ) + break; + } + + return it; +} - wxHeaderIterator it = headers.begin(); - for ( wxHeaderIterator en = headers.end(); it != en; ++it ) +wxHTTP::wxHeaderConstIterator wxHTTP::FindHeader(const wxString& header) const +{ + wxHeaderConstIterator it = m_headers.begin(); + for ( wxHeaderConstIterator en = m_headers.end(); it != en; ++it ) { if ( wxStricmp(it->first, header) == 0 ) break; @@ -101,9 +111,9 @@ void wxHTTP::SetHeader(const wxString& header, const wxString& h_data) wxString wxHTTP::GetHeader(const wxString& header) const { - wxHeaderIterator it = FindHeader(header); + wxHeaderConstIterator it = FindHeader(header); - return it == m_headers.end() ? wxEmptyString : it->second; + return it == m_headers.end() ? wxGetEmptyString() : it->second; } void wxHTTP::SetPostBuffer(const wxString& post_buf) @@ -208,17 +218,25 @@ bool wxHTTP::BuildRequest(const wxString& path, wxHTTP_Req req) break; case wxHTTP_POST: request = wxT("POST"); + if ( GetHeader( wxT("Content-Length") ).IsNull() ) + SetHeader( wxT("Content-Length"), wxString::Format( wxT("%lu"), (unsigned long)m_post_buf.Len() ) ); break; default: return FALSE; } + m_http_response = 0; + // If there is no User-Agent defined, define it. if (GetHeader(wxT("User-Agent")).IsNull()) - SetHeader(wxT("User-Agent"), wxT("wxWindows 2.x")); + SetHeader(wxT("User-Agent"), wxT("wxWidgets 2.x")); SaveState(); - SetFlags(wxSOCKET_NONE); +#if wxUSE_THREADS + SetFlags( wxThread::IsMain() ? wxSOCKET_NONE : wxSOCKET_BLOCK ); +#else + SetFlags( wxSOCKET_NONE ); +#endif Notify(FALSE); wxString buf; @@ -229,7 +247,7 @@ bool wxHTTP::BuildRequest(const wxString& path, wxHTTP_Req req) Write("\r\n", 2); if ( req == wxHTTP_POST ) { - Write(m_post_buf, m_post_buf.Len()); + Write(m_post_buf.mbc_str(), m_post_buf.Len()); m_post_buf = wxEmptyString; } @@ -256,6 +274,8 @@ bool wxHTTP::BuildRequest(const wxString& path, wxHTTP_Req req) token.NextToken(); tmp_str2 = token.NextToken(); + m_http_response = wxAtoi(tmp_str2); + switch (tmp_str2[0u]) { case wxT('1'): /* INFORMATION / SUCCESS */