@@ -41,6 +41,11 @@ namespace http
4141 class arg_comparator ;
4242};
4343
44+ namespace details
45+ {
46+ struct http_response_ptr ;
47+ };
48+
4449using namespace http ;
4550
4651/* *
@@ -61,7 +66,8 @@ class http_response
6166 BASIC_AUTH_FAIL,
6267 SWITCH_PROTOCOL,
6368 LONG_POLLING_RECEIVE,
64- LONG_POLLING_SEND
69+ LONG_POLLING_SEND,
70+ CACHED_CONTENT
6571 };
6672
6773 /* *
@@ -316,10 +322,14 @@ class http_response
316322 std::string send_topic;
317323 struct MHD_Connection * underlying_connection;
318324
319- virtual void get_raw_response (MHD_Response** res, bool * found, webserver* ws = 0x0 );
325+ virtual void get_raw_response (MHD_Response** res, webserver* ws = 0x0 );
326+ virtual void decorate_response (MHD_Response* res);
327+ virtual int enqueue_response (MHD_Connection* connection, MHD_Response* res);
320328
321329 friend class webserver ;
330+ friend struct details ::http_response_ptr;
322331 friend void clone_response (const http_response& hr, http_response** dhr);
332+ friend class cache_response ;
323333};
324334
325335class http_string_response : public http_response
@@ -334,6 +344,8 @@ class http_string_response : public http_response
334344 ): http_response(http_response::STRING_CONTENT, content, response_code, content_type, autodelete) { }
335345
336346 http_string_response (const http_response& b) : http_response(b) { }
347+ private:
348+ friend class webserver ;
337349};
338350
339351class http_byte_response : public http_response
@@ -347,6 +359,8 @@ class http_byte_response : public http_response
347359 const std::string& content_type = " text/plain" ,
348360 bool autodelete = true
349361 ): http_response(http_response::STRING_CONTENT, std::string(content, content_length), response_code, content_type, autodelete) { }
362+ private:
363+ friend class webserver ;
350364};
351365
352366class http_file_response : public http_response
@@ -364,7 +378,9 @@ class http_file_response : public http_response
364378
365379 http_file_response (const http_response& b) : http_response(b) { }
366380 protected:
367- virtual void get_raw_response (MHD_Response** res, bool * found, webserver* ws = 0x0 );
381+ virtual void get_raw_response (MHD_Response** res, webserver* ws = 0x0 );
382+ private:
383+ friend class webserver ;
368384};
369385
370386class http_basic_auth_fail_response : public http_response
@@ -381,6 +397,10 @@ class http_basic_auth_fail_response : public http_response
381397 ) : http_response(http_response::BASIC_AUTH_FAIL, content, response_code, content_type, autodelete, realm) { }
382398
383399 http_basic_auth_fail_response (const http_response& b) : http_response(b) { }
400+ protected:
401+ virtual int enqueue_response (MHD_Connection* connection, MHD_Response* res);
402+ private:
403+ friend class webserver ;
384404};
385405
386406class http_digest_auth_fail_response : public http_response
@@ -400,6 +420,10 @@ class http_digest_auth_fail_response : public http_response
400420 }
401421
402422 http_digest_auth_fail_response (const http_response& b) : http_response(b) { }
423+ protected:
424+ virtual int enqueue_response (MHD_Connection* connection, MHD_Response* res);
425+ private:
426+ friend class webserver ;
403427};
404428
405429class shoutCAST_response : public http_response
@@ -414,6 +438,8 @@ class shoutCAST_response : public http_response
414438 );
415439
416440 shoutCAST_response (const http_response& b) : http_response(b) { }
441+ private:
442+ friend class webserver ;
417443};
418444
419445class switch_protocol_response : public http_response
@@ -429,7 +455,9 @@ class switch_protocol_response : public http_response
429455 {
430456 }
431457 protected:
432- virtual void get_raw_response (MHD_Response** res, bool * found, webserver* ws = 0x0 ) {}
458+ virtual void get_raw_response (MHD_Response** res, webserver* ws = 0x0 ) {}
459+ private:
460+ friend class webserver ;
433461};
434462
435463class long_polling_receive_response : public http_response
@@ -450,12 +478,12 @@ class long_polling_receive_response : public http_response
450478
451479 long_polling_receive_response (const http_response& b) : http_response(b) { }
452480 protected:
453- virtual void get_raw_response (MHD_Response** res, bool * found, webserver* ws = 0x0 );
481+ virtual void get_raw_response (MHD_Response** res, webserver* ws = 0x0 );
454482 private:
455483 static ssize_t data_generator (void * cls, uint64_t pos, char * buf, size_t max);
456-
457484 int connection_id;
458- webserver* ws;
485+ httpserver::webserver* ws;
486+ friend class webserver ;
459487};
460488
461489class long_polling_send_response : public http_response
@@ -472,7 +500,34 @@ class long_polling_send_response : public http_response
472500
473501 long_polling_send_response (const http_response& b) : http_response(b) { }
474502 protected:
475- virtual void get_raw_response (MHD_Response** res, bool * found, webserver* ws = 0x0 );
503+ virtual void get_raw_response (MHD_Response** res, webserver* ws = 0x0 );
504+ private:
505+ friend class webserver ;
506+ };
507+
508+ class cache_response : public http_response
509+ {
510+ public:
511+ cache_response
512+ (
513+ const std::string& key
514+ ) : http_response(http_response::CACHED_CONTENT, key),
515+ ws (0x0 ),
516+ locked_element(false )
517+ {
518+ }
519+
520+ cache_response (const http_response& b) : http_response(b) { }
521+
522+ ~cache_response ();
523+
524+ protected:
525+ virtual void get_raw_response (MHD_Response** res, webserver* ws = 0x0 );
526+ virtual void decorate_response (MHD_Response* res);
527+ private:
528+ webserver* ws;
529+ bool locked_element;
530+ friend class webserver ;
476531};
477532
478533void clone_response (http_response* hr, http_response** dhr);
0 commit comments