]> git.saurik.com Git - wxWidgets.git/blob - include/wx/protocol/http.h
f2ee811ea5fc138d89033ab4f2fc89d90e017967
[wxWidgets.git] / include / wx / protocol / http.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/protocol/http.h
3 // Purpose: HTTP protocol
4 // Author: Guilhem Lavaux
5 // Modified by: Simo Virokannas (authentication, Dec 2005)
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 #include "wx/buffer.h"
21
22 class WXDLLIMPEXP_NET wxHTTP : public wxProtocol
23 {
24 public:
25 wxHTTP();
26 virtual ~wxHTTP();
27
28 virtual bool Connect(const wxString& host, unsigned short port);
29 virtual bool Connect(const wxString& host) { return Connect(host, 0); }
30 virtual bool Connect(const wxSockAddress& addr, bool wait);
31 bool Abort();
32
33 wxInputStream *GetInputStream(const wxString& path);
34
35 wxString GetContentType() const;
36 wxString GetHeader(const wxString& header) const;
37 int GetResponse() const { return m_http_response; }
38
39 void SetMethod(const wxString& method) { m_method = method; }
40 void SetHeader(const wxString& header, const wxString& h_data);
41 bool SetPostText(const wxString& contentType,
42 const wxString& data,
43 const wxMBConv& conv = wxConvUTF8);
44 bool SetPostBuffer(const wxString& contentType, const wxMemoryBuffer& data);
45 void SetProxyMode(bool on);
46
47 /* Cookies */
48 wxString GetCookie(const wxString& cookie) const;
49 bool HasCookies() const { return m_cookies.size() > 0; }
50
51 // Use the other SetPostBuffer() overload or SetPostText() instead.
52 wxDEPRECATED(void SetPostBuffer(const wxString& post_buf));
53
54 protected:
55 typedef wxStringToStringHashMap::iterator wxHeaderIterator;
56 typedef wxStringToStringHashMap::const_iterator wxHeaderConstIterator;
57 typedef wxStringToStringHashMap::iterator wxCookieIterator;
58 typedef wxStringToStringHashMap::const_iterator wxCookieConstIterator;
59
60 bool BuildRequest(const wxString& path, const wxString& method);
61 void SendHeaders();
62 bool ParseHeaders();
63
64 wxString GenerateAuthString(const wxString& user, const wxString& pass) const;
65
66 // find the header in m_headers
67 wxHeaderIterator FindHeader(const wxString& header);
68 wxHeaderConstIterator FindHeader(const wxString& header) const;
69 wxCookieIterator FindCookie(const wxString& cookie);
70 wxCookieConstIterator FindCookie(const wxString& cookie) const;
71
72 // deletes the header value strings
73 void ClearHeaders();
74 void ClearCookies();
75
76 // internal variables:
77
78 wxString m_method;
79 wxStringToStringHashMap m_cookies;
80
81 wxStringToStringHashMap m_headers;
82 bool m_read,
83 m_proxy_mode;
84 wxSockAddress *m_addr;
85 wxMemoryBuffer m_postBuffer;
86 wxString m_contentType;
87 int m_http_response;
88
89 DECLARE_DYNAMIC_CLASS(wxHTTP)
90 DECLARE_PROTOCOL(wxHTTP)
91 wxDECLARE_NO_COPY_CLASS(wxHTTP);
92 };
93
94 #endif // wxUSE_PROTOCOL_HTTP
95
96 #endif // _WX_HTTP_H
97