http_header.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #pragma once
  2. #include "define.h"
  3. #if USE_NET_HTTP_UTIL
  4. #include <map>
  5. #include <vector>
  6. #include <string>
  7. namespace ylib
  8. {
  9. namespace network
  10. {
  11. namespace http
  12. {
  13. class header
  14. {
  15. public:
  16. header();
  17. ~header();
  18. void clear();
  19. void name(const std::string& value);
  20. std::string name() const;
  21. std::map<std::string, std::string> param();
  22. void parse(const std::string& body);
  23. void push(const std::string& value);
  24. void push(const std::string& key, const std::string& value);
  25. /*整段原始值(不按 ; = 拆解)*/
  26. void raw(const std::string& value);
  27. bool exist(const std::string& key) const;
  28. std::string to_string() const;
  29. private:
  30. std::string m_name;
  31. std::string m_raw;
  32. std::map<std::string, std::string> m_param;
  33. std::vector<std::string> m_values;
  34. };
  35. class header_list
  36. {
  37. public:
  38. header_list();
  39. ~header_list();
  40. bool exist(const std::string& name) const;
  41. ylib::network::http::header get(const std::string& name) const;
  42. void set(const std::string& name, const ylib::network::http::header& header);
  43. void set(const std::string& name, const std::string& value);
  44. void del(const std::string& name);
  45. std::map<std::string, std::string> to() const;
  46. size_t size();
  47. void clear();
  48. private:
  49. std::map<std::string, header> m_headers;
  50. };
  51. }
  52. }
  53. }
  54. #endif