- wxHTTPStream(wxHTTP *http) : wxSocketInputStream(*http), m_http(http) {}
- size_t StreamSize() const { return m_httpsize; }
- virtual ~wxHTTPStream(void) { m_http->Abort(); }
+bool wxHTTP::BuildRequest(const wxString& path, wxHTTP_Req req)
+{
+ const wxChar *request;
+
+ switch (req)
+ {
+ case wxHTTP_GET:
+ request = wxT("GET");
+ break;
+
+ case wxHTTP_POST:
+ request = wxT("POST");
+ // Content length must be correct, so always set, possibly
+ // overriding the value set explicitly by a previous call to
+ // SetHeader("Content-Length").
+ if ( !m_postBuffer.IsEmpty() )
+ {
+ wxString len;
+ len << m_postBuffer.GetDataLen();
+
+ SetHeader(wxS("Content-Length"), len);
+ }
+
+ // However if the user had explicitly set the content type, don't
+ // override it with the content type passed to SetPostText().
+ if ( !m_contentType.empty() && GetContentType().empty() )
+ SetHeader(wxS("Content-Type"), m_contentType);
+ break;
+
+ default:
+ return false;
+ }
+
+ m_http_response = 0;
+
+ // If there is no User-Agent defined, define it.
+ if ( GetHeader(wxT("User-Agent")).empty() )
+ SetHeader(wxT("User-Agent"), wxT("wxWidgets 2.x"));
+
+ // Send authentication information
+ if (!m_username.empty() || !m_password.empty()) {
+ SetHeader(wxT("Authorization"), GenerateAuthString(m_username, m_password));
+ }
+
+ SaveState();
+
+ // we may use non blocking sockets only if we can dispatch events from them
+ int flags = wxIsMainThread() && wxApp::IsMainLoopRunning() ? wxSOCKET_NONE
+ : wxSOCKET_BLOCK;
+ // and we must use wxSOCKET_WAITALL to ensure that all data is sent
+ flags |= wxSOCKET_WAITALL;
+ SetFlags(flags);
+ Notify(false);