BBS2chProxyHttpHeaders.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. bool has(const std::string &value);
  31. };
  32. #if (defined(__clang__) && defined(_LIBCPP_VERSION)) || (__cplusplus >= 201103L)
  33. typedef std::shared_ptr<BBS2chProxyHttpHeaderEntry> PBBS2chProxyHttpHeaderEntry;
  34. #else
  35. typedef std::tr1::shared_ptr<BBS2chProxyHttpHeaderEntry> PBBS2chProxyHttpHeaderEntry;
  36. #endif
  37. class BBS2chProxyHttpHeaders {
  38. private:
  39. std::map<std::string, PBBS2chProxyHttpHeaderEntry> _headers;
  40. public:
  41. std::string get(const std::string &name);
  42. bool has(const std::string &name);
  43. bool hasNameAndValue(const std::string &name, const std::string &value);
  44. void add(const std::string &name, const std::string &value);
  45. void add(const char *field);
  46. void set(const std::string &name, const std::string &value);
  47. void remove(const std::string &name);
  48. void clear(void);
  49. curl_slist* appendToCurlSlist(curl_slist *list);
  50. curl_slist* appendToCurlSlist(curl_slist *list, const std::string &name);
  51. std::map<std::string, PBBS2chProxyHttpHeaderEntry>& getMap(void);
  52. #ifdef USE_LUA
  53. static void getObjectMetatableForLua(lua_State *l);
  54. static void getClassDefinitionForLua(lua_State *l);
  55. void getUserdataForLua(lua_State *l);
  56. #endif
  57. };