#pragma hdrstop
#endif
+#if wxUSE_SOCKETS
+
#ifndef WX_PRECOMP
#endif
{
wxNode *node = m_headers.Find(header);
if (!node)
- return (char *)NULL;
+ return wxEmptyString;
return *((wxString *)node->Data());
}
{
wxNode *head = m_headers.First();
- while (head) {
+ while (head)
+ {
wxString *str = (wxString *)head->Data();
- char buf[100];
- sprintf(buf, "%s: %s\n\r", head->GetKeyString()/*key.string*/, str->GetData());
- Write(buf, strlen(buf));
+ wxString buf;
+ buf.Printf("%s: %s\n\r", head->GetKeyString(), str->GetData());
+
+ Write(buf, buf.Len());
head = head->Next();
}
if (line.Length() == 0)
break;
+ printf("Header: %s\n", WXSTRINGCAST line);
int pos = line.Find(':');
if (pos == -1)
return FALSE;
return TRUE;
}
-bool wxHTTP::Connect(wxSockAddress& addr)
+bool wxHTTP::Connect(wxSockAddress& addr, bool WXUNUSED(wait))
{
struct sockaddr *raw_addr;
size_t len;
return FALSE;
}
+ SaveState();
+ Notify(FALSE);
+ SetFlags(WAITALL);
+
sprintf(buf, "%s %s HTTP/1.0\n\r", tmp_buf, (const char *)path);
Write(buf, strlen(buf));
SendHeaders();
wxString tmp_str;
m_error = GetLine(this, tmp_str);
- if (m_error != wxPROTO_NOERR)
+ if (m_error != wxPROTO_NOERR) {
+ RestoreState();
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");
+ RestoreState();
return TRUE;
}
wxStringTokenizer token(tmp_str,' ');
wxString tmp_str2;
+ bool ret_value;
token.NextToken();
tmp_str2 = token.NextToken();
break;
default:
m_error = wxPROTO_NOFILE;
+ RestoreState();
return FALSE;
}
- return ParseHeaders();
+ ret_value = ParseHeaders();
+ RestoreState();
+ return ret_value;
}
class wxHTTPStream : public wxSocketInputStream {
public:
wxHTTP *m_http;
+ size_t m_httpsize;
+
wxHTTPStream(wxHTTP *http) : wxSocketInputStream(*http), m_http(http) {}
+ size_t StreamSize() const { return m_httpsize; }
virtual ~wxHTTPStream(void) { m_http->Abort(); }
};
if (!BuildRequest(path, wxHTTP_GET))
return NULL;
+ printf("Len = %s\n", WXSTRINGCAST GetHeader("Content-Length"));
+ if (!GetHeader("Content-Length").IsEmpty())
+ inp_stream->m_httpsize = atoi(WXSTRINGCAST GetHeader("Content-Length"));
+
return inp_stream;
}
+
+#endif
+ // wxUSE_SOCKETS