]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: 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 | ||
21 | class WXDLLIMPEXP_NET wxHTTP : public wxProtocol | |
22 | { | |
23 | public: | |
24 | wxHTTP(); | |
25 | virtual ~wxHTTP(); | |
26 | ||
27 | virtual bool Connect(const wxString& host, unsigned short port); | |
28 | virtual bool Connect(const wxString& host) { return Connect(host, 0); } | |
29 | virtual bool Connect(const wxSockAddress& addr, bool wait); | |
30 | bool Abort(); | |
31 | ||
32 | wxInputStream *GetInputStream(const wxString& path); | |
33 | ||
34 | wxString GetContentType() const; | |
35 | wxString GetHeader(const wxString& header) const; | |
36 | int GetResponse() const { return m_http_response; } | |
37 | ||
38 | void SetHeader(const wxString& header, const wxString& h_data); | |
39 | void SetPostBuffer(const wxString& post_buf); | |
40 | void SetProxyMode(bool on); | |
41 | ||
42 | /* Cookies */ | |
43 | wxString GetCookie(const wxString& cookie) const; | |
44 | bool HasCookies() const { return m_cookies.size() > 0; } | |
45 | ||
46 | protected: | |
47 | enum wxHTTP_Req | |
48 | { | |
49 | wxHTTP_GET, | |
50 | wxHTTP_POST, | |
51 | wxHTTP_HEAD | |
52 | }; | |
53 | ||
54 | typedef wxStringToStringHashMap::iterator wxHeaderIterator; | |
55 | typedef wxStringToStringHashMap::const_iterator wxHeaderConstIterator; | |
56 | typedef wxStringToStringHashMap::iterator wxCookieIterator; | |
57 | typedef wxStringToStringHashMap::const_iterator wxCookieConstIterator; | |
58 | ||
59 | bool BuildRequest(const wxString& path, wxHTTP_Req req); | |
60 | void SendHeaders(); | |
61 | bool ParseHeaders(); | |
62 | ||
63 | wxString GenerateAuthString(const wxString& user, const wxString& pass) const; | |
64 | ||
65 | // find the header in m_headers | |
66 | wxHeaderIterator FindHeader(const wxString& header); | |
67 | wxHeaderConstIterator FindHeader(const wxString& header) const; | |
68 | wxCookieIterator FindCookie(const wxString& cookie); | |
69 | wxCookieConstIterator FindCookie(const wxString& cookie) const; | |
70 | ||
71 | // deletes the header value strings | |
72 | void ClearHeaders(); | |
73 | void ClearCookies(); | |
74 | ||
75 | // internal variables: | |
76 | ||
77 | wxStringToStringHashMap m_cookies; | |
78 | ||
79 | wxStringToStringHashMap m_headers; | |
80 | bool m_read, | |
81 | m_proxy_mode; | |
82 | wxSockAddress *m_addr; | |
83 | wxString m_post_buf; | |
84 | int m_http_response; | |
85 | ||
86 | DECLARE_DYNAMIC_CLASS(wxHTTP) | |
87 | DECLARE_PROTOCOL(wxHTTP) | |
88 | wxDECLARE_NO_COPY_CLASS(wxHTTP); | |
89 | }; | |
90 | ||
91 | #endif // wxUSE_PROTOCOL_HTTP | |
92 | ||
93 | #endif // _WX_HTTP_H | |
94 |