http.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. // Copyright: (c) 1997, 1998 Guilhem Lavaux
  8. // Licence: wxWindows licence
  9. /////////////////////////////////////////////////////////////////////////////
  10. #ifndef _WX_HTTP_H
  11. #define _WX_HTTP_H
  12. #include "wx/defs.h"
  13. #if wxUSE_PROTOCOL_HTTP
  14. #include "wx/hashmap.h"
  15. #include "wx/protocol/protocol.h"
  16. #include "wx/buffer.h"
  17. class WXDLLIMPEXP_NET wxHTTP : public wxProtocol
  18. {
  19. public:
  20. wxHTTP();
  21. virtual ~wxHTTP();
  22. virtual bool Connect(const wxString& host, unsigned short port);
  23. virtual bool Connect(const wxString& host) { return Connect(host, 0); }
  24. virtual bool Connect(const wxSockAddress& addr, bool wait);
  25. bool Abort();
  26. wxInputStream *GetInputStream(const wxString& path);
  27. wxString GetContentType() const;
  28. wxString GetHeader(const wxString& header) const;
  29. int GetResponse() const { return m_http_response; }
  30. void SetMethod(const wxString& method) { m_method = method; }
  31. void SetHeader(const wxString& header, const wxString& h_data);
  32. bool SetPostText(const wxString& contentType,
  33. const wxString& data,
  34. const wxMBConv& conv = wxConvUTF8);
  35. bool SetPostBuffer(const wxString& contentType, const wxMemoryBuffer& data);
  36. void SetProxyMode(bool on);
  37. /* Cookies */
  38. wxString GetCookie(const wxString& cookie) const;
  39. bool HasCookies() const { return m_cookies.size() > 0; }
  40. // Use the other SetPostBuffer() overload or SetPostText() instead.
  41. wxDEPRECATED(void SetPostBuffer(const wxString& post_buf));
  42. protected:
  43. typedef wxStringToStringHashMap::iterator wxHeaderIterator;
  44. typedef wxStringToStringHashMap::const_iterator wxHeaderConstIterator;
  45. typedef wxStringToStringHashMap::iterator wxCookieIterator;
  46. typedef wxStringToStringHashMap::const_iterator wxCookieConstIterator;
  47. bool BuildRequest(const wxString& path, const wxString& method);
  48. void SendHeaders();
  49. bool ParseHeaders();
  50. wxString GenerateAuthString(const wxString& user, const wxString& pass) const;
  51. // find the header in m_headers
  52. wxHeaderIterator FindHeader(const wxString& header);
  53. wxHeaderConstIterator FindHeader(const wxString& header) const;
  54. wxCookieIterator FindCookie(const wxString& cookie);
  55. wxCookieConstIterator FindCookie(const wxString& cookie) const;
  56. // deletes the header value strings
  57. void ClearHeaders();
  58. void ClearCookies();
  59. // internal variables:
  60. wxString m_method;
  61. wxStringToStringHashMap m_cookies;
  62. wxStringToStringHashMap m_headers;
  63. bool m_read,
  64. m_proxy_mode;
  65. wxSockAddress *m_addr;
  66. wxMemoryBuffer m_postBuffer;
  67. wxString m_contentType;
  68. int m_http_response;
  69. DECLARE_DYNAMIC_CLASS(wxHTTP)
  70. DECLARE_PROTOCOL(wxHTTP)
  71. wxDECLARE_NO_COPY_CLASS(wxHTTP);
  72. };
  73. #endif // wxUSE_PROTOCOL_HTTP
  74. #endif // _WX_HTTP_H