00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef restcgi_method_h
00023 #define restcgi_method_h
00024 #include "apidefs.h"
00025 #include "method_e.h"
00026 #include "hdr.h"
00027 #include "content.h"
00028 #include "status_code_e.h"
00029 #include <uripp/path.h>
00030 #include <uripp/query.h>
00031 #include <string>
00032 #include <boost/shared_ptr.hpp>
00033 namespace restcgi {
00034 class env;
00035 class endpoint;
00036 class icontent;
00037 class ocontent;
00065 class RESTCGI_API method {
00066 public:
00067 typedef boost::shared_ptr<method> pointer;
00068 typedef boost::shared_ptr<const method> const_pointer;
00069 typedef restcgi::env env_type;
00070 typedef restcgi::endpoint endpoint_type;
00071 typedef boost::shared_ptr<endpoint_type> endpoint_pointer;
00072 typedef restcgi::icontent icontent_type;
00073 typedef restcgi::ocontent ocontent_type;
00074 typedef boost::shared_ptr<icontent_type> icontent_pointer;
00075 typedef boost::shared_ptr<ocontent_type> ocontent_pointer;
00076 typedef restcgi::request_hdr request_hdr_type;
00077 typedef restcgi::response_hdr response_hdr_type;
00078 typedef uripp::path uri_path_type;
00079 typedef uripp::query uri_query_type;
00080 virtual ~method();
00081 const method_e& e() const {return e_;}
00082
00086 const uri_path_type& uri_path() const {return uri_path_;}
00087 const uri_query_type& uri_query() const {return uri_query_;}
00088 const request_hdr_type& request_hdr() const {return request_hdr_;}
00089 icontent_pointer icontent() const {return icontent_;}
00090 ocontent_pointer ocontent() const {return ocontent_;}
00091
00094 void respond(const status_code_e& sc = status_code_e::OK, const response_hdr_type& rh = response_hdr_type());
00099 ocontent_pointer respond(const content_hdr& ch, const status_code_e& sc = status_code_e::OK, const response_hdr_type& rh = response_hdr_type());
00100 bool responded() const {return responded_;}
00101 const env_type& env() const;
00102 endpoint_pointer endpoint() const {return endpoint_;}
00103 static const char QP_REST_PUT[8];
00104 static const char QP_REST_DELETE[11];
00105 private:
00106 method(const method&);
00107 method& operator =(const method&);
00108 method(const method_e& e, const endpoint_pointer& ep);
00109 friend class endpoint;
00111 static pointer create(const endpoint_pointer& ep);
00112 void respond(const status_code_e& sc, const response_hdr_type& rh, const content_hdr& ch, bool has_content);
00113 static void respond(endpoint_pointer ep, const status_code_e& sc, const response_hdr_type& rh = response_hdr_type(), const content_hdr& ch = content_hdr());
00114 method_e e_;
00116 endpoint_pointer endpoint_;
00117 uri_path_type uri_path_;
00118 uri_query_type uri_query_;
00119 bool responded_;
00120 request_hdr_type request_hdr_;
00121 icontent_pointer icontent_;
00122 ocontent_pointer ocontent_;
00123 };
00124 }
00125 #endif