added support for POST method and alternate ports (part of patch 649438)
[wxWidgets.git] / include / wx / protocol / http.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: http.h
3 // Purpose: HTTP protocol
4 // Author: Guilhem Lavaux
5 // Modified by:
6 // Created: August 1997
7 // RCS-ID: $Id$
8 // Copyright: (c) 1997, 1998 Guilhem Lavaux
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_HTTP_H
12 #define _WX_HTTP_H
13
14 #include "wx/defs.h"
15
16 #if wxUSE_PROTOCOL_HTTP
17
18 #include "wx/hashmap.h"
19 #include "wx/protocol/protocol.h"
20
21 WX_DECLARE_EXPORTED_STRING_HASH_MAP( wxString, wxStringToStringHashMap );
22
23 class WXDLLIMPEXP_BASE wxHTTP : public wxProtocol {
24 DECLARE_DYNAMIC_CLASS(wxHTTP)
25 DECLARE_PROTOCOL(wxHTTP)
26 protected:
27 wxProtocolError m_perr;
28 wxStringToStringHashMap m_headers;
29 bool m_read, m_proxy_mode;
30 wxSockAddress *m_addr;
31 wxString m_post_buf;
32 public:
33 wxHTTP();
34 ~wxHTTP();
35
36 bool Connect(const wxString& host, unsigned short port = 0);
37 bool Connect(wxSockAddress& addr, bool wait);
38 bool Abort();
39 wxInputStream *GetInputStream(const wxString& path);
40 inline wxProtocolError GetError() { return m_perr; }
41 wxString GetContentType();
42
43 void SetHeader(const wxString& header, const wxString& h_data);
44 wxString GetHeader(const wxString& header);
45 void SetPostBuffer(const wxString& post_buf);
46
47 void SetProxyMode(bool on);
48
49 protected:
50 typedef enum {
51 wxHTTP_GET,
52 wxHTTP_POST,
53 wxHTTP_HEAD
54 } wxHTTP_Req;
55 bool BuildRequest(const wxString& path, wxHTTP_Req req);
56 void SendHeaders();
57 bool ParseHeaders();
58
59 // deletes the header value strings
60 void ClearHeaders();
61
62 DECLARE_NO_COPY_CLASS(wxHTTP)
63 };
64
65 #endif // wxUSE_PROTOCOL_HTTP
66
67 #endif // _WX_HTTP_H
68