@@ -59,6 +59,58 @@ class bad_caching_attempt: public std::exception
5959 }
6060};
6161
62+ class http_file_response ;
63+ class http_basic_auth_fail_response ;
64+ class http_digest_auth_fail_response ;
65+ class switch_protocol_response ;
66+ class long_polling_receive_response ;
67+ class long_polling_send_response ;
68+ class cache_response ;
69+ class deferred_response ;
70+
71+ #define SPECIALIZE_RESPONSE_FOR (TYPE, S1, S2, S3 ) \
72+ http_response \
73+ ( \
74+ const TYPE* response_type, \
75+ const std::string& content, \
76+ int response_code,\
77+ const std::string& content_type,\
78+ bool autodelete,\
79+ const std::string& realm,\
80+ const std::string& opaque,\
81+ bool reload_nonce,\
82+ const std::vector<std::string>& topics,\
83+ int keepalive_secs,\
84+ const std::string keepalive_msg,\
85+ const std::string send_topic,\
86+ cache_entry* ce\
87+ ):\
88+ content (content),\
89+ response_code (response_code),\
90+ autodelete (autodelete),\
91+ realm (realm),\
92+ opaque (opaque),\
93+ reload_nonce (reload_nonce),\
94+ fp (-1 ),\
95+ filename (content),\
96+ topics (topics),\
97+ keepalive_secs (keepalive_secs),\
98+ keepalive_msg (keepalive_msg),\
99+ send_topic (send_topic),\
100+ underlying_connection (0x0 ),\
101+ ca (0x0 ),\
102+ closure_data (0x0 ),\
103+ ce (ce),\
104+ get_raw_response (this , &http_response::get_raw_response_## S1),\
105+ decorate_response (this , &http_response::decorate_response_## S2),\
106+ enqueue_response (this , &http_response::enqueue_response_## S3),\
107+ completed (false ),\
108+ ws (0x0 ),\
109+ connection_id (0x0 )\
110+ {\
111+ set_header (http_utils::http_header_content_type, content_type);\
112+ }
113+
62114/* *
63115 * Class representing an abstraction for an Http Response. It is used from classes using these apis to send information through http protocol.
64116**/
@@ -71,10 +123,10 @@ class http_response
71123 * @param response_code The response code to set for the request.
72124 * @param response_type param indicating if the content have to be read from a string or from a file
73125 **/
74- template <typename T >
126+ template <class TYPE >
75127 http_response
76128 (
77- const T* response_type = 0x0 ,
129+ const TYPE* t ,
78130 const std::string& content = " " ,
79131 int response_code = 200 ,
80132 const std::string& content_type = " text/plain" ,
@@ -113,6 +165,16 @@ class http_response
113165 {
114166 set_header (http_utils::http_header_content_type, content_type);
115167 }
168+
169+ SPECIALIZE_RESPONSE_FOR (http_file_response, file, str, str);
170+ SPECIALIZE_RESPONSE_FOR (http_basic_auth_fail_response, str, str, basic);
171+ SPECIALIZE_RESPONSE_FOR (http_digest_auth_fail_response, str, str, digest);
172+ SPECIALIZE_RESPONSE_FOR (switch_protocol_response, switch_r, str, str);
173+ SPECIALIZE_RESPONSE_FOR (long_polling_receive_response, lp_receive, str, str);
174+ SPECIALIZE_RESPONSE_FOR (long_polling_send_response, lp_send, str, str);
175+ SPECIALIZE_RESPONSE_FOR (cache_response, cache, cache, str);
176+ SPECIALIZE_RESPONSE_FOR (deferred_response, deferred, deferred, str);
177+
116178 /* *
117179 * Copy constructor
118180 * @param b The http_response object to copy attributes value from.
@@ -425,68 +487,6 @@ class http_response
425487 http_response& operator =(const http_response& b);
426488};
427489
428- class http_file_response ;
429- class http_basic_auth_fail_response ;
430- class http_digest_auth_fail_response ;
431- class switch_protocol_response ;
432- class long_polling_receive_response ;
433- class long_polling_send_response ;
434- class cache_response ;
435- class deferred_response ;
436-
437- #define SPECIALIZE_RESPONSE_FOR (TYPE, S1, S2, S3 ) \
438- template <> \
439- inline http_response::http_response<TYPE> \
440- ( \
441- const TYPE* response_type, \
442- const std::string& content, \
443- int response_code,\
444- const std::string& content_type,\
445- bool autodelete,\
446- const std::string& realm,\
447- const std::string& opaque,\
448- bool reload_nonce,\
449- const std::vector<std::string>& topics,\
450- int keepalive_secs,\
451- const std::string keepalive_msg,\
452- const std::string send_topic,\
453- cache_entry* ce\
454- ):\
455- content (content),\
456- response_code (response_code),\
457- autodelete (autodelete),\
458- realm (realm),\
459- opaque (opaque),\
460- reload_nonce (reload_nonce),\
461- fp (-1 ),\
462- filename (content),\
463- topics (topics),\
464- keepalive_secs (keepalive_secs),\
465- keepalive_msg (keepalive_msg),\
466- send_topic (send_topic),\
467- underlying_connection (0x0 ),\
468- ca (0x0 ),\
469- closure_data (0x0 ),\
470- ce (ce),\
471- get_raw_response (this , &http_response::get_raw_response_## S1),\
472- decorate_response (this , &http_response::decorate_response_## S2),\
473- enqueue_response (this , &http_response::enqueue_response_## S3),\
474- completed (false ),\
475- ws (0x0 ),\
476- connection_id (0x0 )\
477- {\
478- set_header (http_utils::http_header_content_type, content_type);\
479- }
480-
481- SPECIALIZE_RESPONSE_FOR (http_file_response, file, str, str);
482- SPECIALIZE_RESPONSE_FOR (http_basic_auth_fail_response, str, str, basic);
483- SPECIALIZE_RESPONSE_FOR (http_digest_auth_fail_response, str, str, digest);
484- SPECIALIZE_RESPONSE_FOR (switch_protocol_response, switch_r, str, str);
485- SPECIALIZE_RESPONSE_FOR (long_polling_receive_response, lp_receive, str, str);
486- SPECIALIZE_RESPONSE_FOR (long_polling_send_response, lp_send, str, str);
487- SPECIALIZE_RESPONSE_FOR (cache_response, cache, cache, str);
488- SPECIALIZE_RESPONSE_FOR (deferred_response, deferred, deferred, str);
489-
490490class http_string_response : public http_response
491491{
492492 public:
0 commit comments