- char *tmp_buf;
- char buf[HTTP_BSIZE];
-
- switch (req) {
- case wxHTTP_GET:
- tmp_buf = "GET";
- break;
- default:
- return FALSE;
- }
-
- sprintf(buf, "%s %s HTTP/1.0\n\r", tmp_buf, (const char *)path);
- Write(buf, strlen(buf));
- SendHeaders();
- sprintf(buf, "\n\r");
- Write(buf, strlen(buf));
-
- wxString tmp_str;
-
- m_error = GetLine(this, tmp_str);
- if (m_error != wxPROTO_NOERR)
- return FALSE;
-
- if (!tmp_str.Contains("HTTP/")) {
- // TODO: support HTTP v0.9 which can have no header.
- SetHeader("Content-Length", "-1");
- SetHeader("Content-Type", "none/none");
- return TRUE;
- }
-
- wxStringTokenizer token(tmp_str,' ');
- wxString tmp_str2;
-
- token.NextToken();
- tmp_str2 = token.NextToken();
-
- switch (atoi(tmp_str2)) {
- case 200:
- break;
- default:
- m_error = wxPROTO_NOFILE;
- return FALSE;
- }
-
- return ParseHeaders();
+ 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);
+
+ wxString buf;
+ buf.Printf(wxT("%s %s HTTP/1.0\r\n"), request, path.c_str());
+ const wxWX2MBbuf pathbuf = wxConvLocal.cWX2MB(buf);
+ Write(pathbuf, strlen(wxMBSTRINGCAST pathbuf));
+ SendHeaders();
+ Write("\r\n", 2);
+
+ if ( req == wxHTTP_POST ) {
+ Write(m_post_buf.mbc_str(), m_post_buf.Len());
+ m_post_buf = wxEmptyString;
+ }
+
+ wxString tmp_str;
+ m_perr = ReadLine(this, tmp_str);
+ if (m_perr != wxPROTO_NOERR) {
+ RestoreState();
+ return false;
+ }
+
+ if (!tmp_str.Contains(wxT("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(wxT("Content-Length"), wxT("-1"));
+ SetHeader(wxT("Content-Type"), wxT("none/none"));
+ RestoreState();
+ return true;
+ }
+
+ wxStringTokenizer token(tmp_str,wxT(' '));
+ wxString tmp_str2;
+ bool ret_value;
+
+ token.NextToken();
+ tmp_str2 = token.NextToken();
+
+ m_http_response = wxAtoi(tmp_str2);
+
+ switch (tmp_str2[0u])
+ {
+ case wxT('1'):
+ /* INFORMATION / SUCCESS */
+ break;
+
+ case wxT('2'):
+ /* SUCCESS */
+ break;
+
+ case wxT('3'):
+ /* REDIRECTION */
+ break;
+
+ default:
+ m_perr = wxPROTO_NOFILE;
+ RestoreState();
+ return false;
+ }
+
+ ret_value = ParseHeaders();
+ RestoreState();
+ return ret_value;