BBS2chProxyHttpHeaders.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #pragma once
  2. #include <map>
  3. #include <vector>
  4. #include <string>
  5. #if (defined(__clang__) && defined(_LIBCPP_VERSION)) || (__cplusplus >= 201103L)
  6. #include <memory>
  7. #else
  8. #include <tr1/memory>
  9. #endif
  10. #include <curl/curl.h>
  11. #ifdef USE_LUA
  12. #include <lua.hpp>
  13. #endif
  14. class BBS2chProxyHttpHeaderEntry {
  15. private:
  16. std::string _name;
  17. std::vector<std::string> _values;
  18. public:
  19. BBS2chProxyHttpHeaderEntry(const std::string &name, const std::string &value)
  20. {
  21. _name = name;
  22. _values.push_back(value);
  23. }
  24. std::string& getName(void);
  25. std::string getValue(void);
  26. std::string getFull(void);
  27. std::vector<std::string>& getValueList(void);
  28. void add(const std::string &value);
  29. void set(const std::string &value);
  30. };
  31. #if (defined(__clang__) && defined(_LIBCPP_VERSION)) || (__cplusplus >= 201103L)
  32. typedef std::shared_ptr<BBS2chProxyHttpHeaderEntry> PBBS2chProxyHttpHeaderEntry;
  33. #else
  34. typedef std::tr1::shared_ptr<BBS2chProxyHttpHeaderEntry> PBBS2chProxyHttpHeaderEntry;
  35. #endif
  36. class BBS2chProxyHttpHeaders {
  37. private:
  38. std::map<std::string, PBBS2chProxyHttpHeaderEntry> _headers;
  39. public:
  40. std::string get(const std::string &name);
  41. bool has(const std::string &name);
  42. void add(const std::string &name, const std::string &value);
  43. void add(const char *field);
  44. void set(const std::string &name, const std::string &value);
  45. void remove(const std::string &name);
  46. void clear(void);
  47. curl_slist* appendToCurlSlist(curl_slist *list);
  48. curl_slist* appendToCurlSlist(curl_slist *list, const std::string &name);
  49. std::map<std::string, PBBS2chProxyHttpHeaderEntry>& getMap(void);
  50. #ifdef USE_LUA
  51. static void getObjectMetatableForLua(lua_State *l);
  52. static void getClassDefinitionForLua(lua_State *l);
  53. void getUserdataForLua(lua_State *l);
  54. #endif
  55. };