BBS2chProxyHttpHeaders.h 2.0 KB

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