- wxChar *tmp_buf;
- wxChar buf[200]; // 200 is arbitrary.
- wxString tmp_str = path;
-
- // If there is no User-Agent defined, define it.
- if (GetHeader(T("User-Agent")).IsNull())
- SetHeader(T("User-Agent"), T("wxWindows 2.x"));
-
- switch (req) {
- case wxHTTP_GET:
- tmp_buf = T("GET(");
- break;
- default:
- return FALSE;
- }
-
- SaveState();
- SetFlags(NONE);
- Notify(FALSE);
-
- wxSprintf(buf, T("%s %s HTTP/1.0\n\r"), tmp_buf, tmp_str.GetData());
- const wxWX2MBbuf pathbuf = wxConvLibc.cWX2MB(buf);
- Write(pathbuf, strlen(wxMBSTRINGCAST pathbuf));
- SendHeaders();
- Write("\n\r", 2);
-
- m_perr = GetLine(this, tmp_str);
- if (m_perr != wxPROTO_NOERR) {
- RestoreState();
- return FALSE;
- }
-
- if (!tmp_str.Contains(T("HTTP/"))) {
- // TODO: support HTTP v0.9 which can have no header.
- // FIXME: tmp_str is not put back in the in-queue of the socket.
- SetHeader(T("Content-Length"), T("-1"));
- SetHeader(T("Content-Type"), T("none/none"));
- RestoreState();
- return TRUE;
- }
-
- wxStringTokenizer token(tmp_str,T(' '));
- wxString tmp_str2;
- bool ret_value;
-
- token.NextToken();
- tmp_str2 = token.NextToken();
-
- switch (tmp_str2[(unsigned int) 0]) {
- case T('1'):
- /* INFORMATION / SUCCESS */
- break;
- case T('2'):
- /* SUCCESS */
- break;
- case T('3'):
- /* REDIRECTION */
- break;
- default:
- m_perr = wxPROTO_NOFILE;
- RestoreState();
- return FALSE;
- }
+ const wxChar *request;
+
+ switch (req)
+ {
+ case wxHTTP_GET:
+ request = wxT("GET");
+ 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("wxWidgets 2.x"));
+
+ SaveState();
+
+ // we may use non blocking sockets only if we can dispatch events from them
+ SetFlags( wxIsMainThread() && wxApp::IsMainLoopRunning() ? wxSOCKET_NONE
+ : wxSOCKET_BLOCK );
+ Notify(false);