ChipMaster's trial hacks on C++CMS starting with v1.2.1. Not sure I'll follow on with the v2 since it looks to be breaking and mostly frivolous.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

170 lines
4.4 KiB

  1. #ifndef CPPCMS_HTTP_RESPONSE_H
  2. #define CPPCMS_HTTP_RESPONSE_H
  3. #include "defs.h"
  4. #include "noncopyable.h"
  5. #include "hold_ptr.h"
  6. #include <string>
  7. #include <iostream>
  8. #include "cstdint.h"
  9. namespace cppcms {
  10. class cache_interface;
  11. namespace impl { namespace cgi { class connection; }}
  12. namespace http {
  13. class context;
  14. class cookie;
  15. class CPPCMS_API response : public util::noncopyable {
  16. public:
  17. // RFC 2616 sec. 6.1.1
  18. typedef enum {
  19. continue_transfer = 100,
  20. switching_protocol = 101,
  21. ok = 200,
  22. created = 201,
  23. accepted = 202,
  24. non_authoritative_information = 203,
  25. no_content = 204,
  26. reset_content = 205,
  27. partial_content = 206,
  28. multiple_choices = 300,
  29. moved_permanently = 301,
  30. found = 302,
  31. see_other = 303,
  32. not_modified = 304,
  33. use_proxy = 305,
  34. temporary_redirect = 307,
  35. bad_request = 400,
  36. unauthorized = 401,
  37. payment_required = 402,
  38. forbidden = 403,
  39. not_found = 404,
  40. method_not_allowed = 405,
  41. not_acceptable = 406,
  42. proxy_authentication_required = 407,
  43. request_time_out = 408,
  44. conflict = 409,
  45. gone = 410,
  46. precondition_failed = 412,
  47. request_entity_too_large = 413,
  48. request_uri_too_large = 414,
  49. unsupported_media_type = 415,
  50. requested_range_not_satisfiable = 416,
  51. expectation_failed = 417,
  52. internal_server_error = 500,
  53. not_implemented = 501,
  54. bad_gateway = 502,
  55. service_unavailable = 503,
  56. gateway_timeout = 504,
  57. http_version_not_supported = 505
  58. } status_type;
  59. typedef enum {
  60. // synchronous io
  61. normal, // write request, use buffering, possible compression,
  62. nogzip, // as normal but disable gzip
  63. raw, // user writes its own headers to stream directly
  64. asynchronous,
  65. // the data is buffered and never transferred
  66. // untill it is requested explicitly
  67. asynchronous_raw
  68. // the data is buffered and nevet transferred
  69. // untill it is requested explicitly, headers are not written
  70. } io_mode_type;
  71. // Standard HTTP Response Headers RFC 2616
  72. void accept_ranges(std::string const &);
  73. void age(unsigned seconds);
  74. void allow(std::string const &);
  75. void cache_control(std::string const &);
  76. void content_encoding(std::string const &);
  77. void content_language(std::string const &);
  78. void content_length(unsigned long long len);
  79. void content_location(std::string const &);
  80. void content_md5(std::string const &);
  81. void content_range(std::string const &);
  82. void content_type(std::string const &);
  83. void date(time_t);
  84. void etag(std::string const &);
  85. void expires(time_t);
  86. void last_modified(time_t);
  87. void location(std::string const &);
  88. void pragma(std::string const &);
  89. void proxy_authenticate(std::string const &);
  90. void retry_after(std::string const &);
  91. void retry_after(unsigned);
  92. void status(int code);
  93. void status(int code,std::string const &message);
  94. void trailer(std::string const &);
  95. void transfer_encoding(std::string const &);
  96. void vary(std::string const &);
  97. void via(std::string const &);
  98. void warning(std::string const &);
  99. void www_authenticate(std::string const &);
  100. void set_header(std::string const &name,std::string const &value);
  101. std::string get_header(std::string const &name);
  102. void erase_header(std::string const &);
  103. void clear();
  104. void set_content_header(std::string const &content_type);
  105. void set_html_header();
  106. void set_xhtml_header();
  107. void set_plain_text_header();
  108. void set_redirect_header(std::string const &location,int status = found);
  109. void set_cookie(cookie const &);
  110. void make_error_response(int stat,std::string const &msg = std::string());
  111. io_mode_type io_mode();
  112. void io_mode(io_mode_type);
  113. std::ostream &out();
  114. static std::string make_http_time(time_t);
  115. static char const *status_to_string(int status);
  116. bool some_output_was_written();
  117. void finalize();
  118. response(context &);
  119. ~response();
  120. private:
  121. friend class impl::cgi::connection;
  122. friend class ::cppcms::cache_interface;
  123. void copy_to_cache();
  124. std::string copied_data();
  125. bool need_gzip();
  126. std::pair<char const *,size_t> output();
  127. void write_http_headers(std::ostream &);
  128. std::string get_async_chunk();
  129. struct data;
  130. util::hold_ptr<data> d;
  131. context &context_;
  132. std::ostream *stream_;
  133. io_mode_type io_mode_;
  134. uint32_t disable_compression_ : 1;
  135. uint32_t ostream_requested_ : 1;
  136. uint32_t copy_to_cache_ : 1;
  137. uint32_t finalized_ : 1;
  138. uint32_t reserved_ : 28;
  139. };
  140. } /* http */
  141. } /* cppcms */
  142. #endif