@@ -39,6 +39,14 @@ http_resource::http_resource()
3939 this ->allowed_methods [MHD_HTTP_METHOD_TRACE] = true ;
4040 this ->allowed_methods [MHD_HTTP_METHOD_CONNECT] = true ;
4141 this ->allowed_methods [MHD_HTTP_METHOD_OPTIONS] = true ;
42+ #ifdef DEBUG
43+ std::map<std::string, bool >::iterator it;
44+ for (it = allowed_methods.begin (); it != allowed_methods.end (); it++)
45+ {
46+ std::cout << (*it).first << " -> " << (*it).second << std::endl;
47+ }
48+ #endif // DEBUG
49+
4250}
4351
4452http_resource::~http_resource ()
@@ -47,14 +55,7 @@ http_resource::~http_resource()
4755
4856http_response http_resource::render (const http_request& r)
4957{
50- if (this ->is_allowed (r.get_method ()))
51- {
52- return this ->render_404 ();
53- }
54- else
55- {
56- return this ->render_405 ();
57- }
58+ return this ->render_404 ();
5859}
5960
6061http_response http_resource::render_404 ()
@@ -120,41 +121,48 @@ http_response http_resource::route_request(const http_request& r)
120121
121122 http_response res;
122123
123- if (method == MHD_HTTP_METHOD_GET)
124- {
125- res = this ->render_GET (r);
126- }
127- else if (method == MHD_HTTP_METHOD_POST)
124+ if (this ->is_allowed (method))
128125 {
129- res = this ->render_POST (r);
130- }
131- else if (method == MHD_HTTP_METHOD_PUT)
132- {
133- res = this ->render_PUT (r);
134- }
135- else if (method == MHD_HTTP_METHOD_DELETE)
136- {
137- res = this ->render_DELETE (r);
138- }
139- else if (method == MHD_HTTP_METHOD_HEAD)
140- {
141- res = this ->render_HEAD (r);
142- }
143- else if (method == MHD_HTTP_METHOD_TRACE)
144- {
145- res = this ->render_TRACE (r);
146- }
147- else if (method == MHD_HTTP_METHOD_OPTIONS)
148- {
149- res = this ->render_OPTIONS (r);
150- }
151- else if (method == MHD_HTTP_METHOD_CONNECT)
152- {
153- res = this ->render_CONNECT (r);
154- }
155- else
126+ if (method == MHD_HTTP_METHOD_GET)
127+ {
128+ res = this ->render_GET (r);
129+ }
130+ else if (method == MHD_HTTP_METHOD_POST)
131+ {
132+ res = this ->render_POST (r);
133+ }
134+ else if (method == MHD_HTTP_METHOD_PUT)
135+ {
136+ res = this ->render_PUT (r);
137+ }
138+ else if (method == MHD_HTTP_METHOD_DELETE)
139+ {
140+ res = this ->render_DELETE (r);
141+ }
142+ else if (method == MHD_HTTP_METHOD_HEAD)
143+ {
144+ res = this ->render_HEAD (r);
145+ }
146+ else if (method == MHD_HTTP_METHOD_TRACE)
147+ {
148+ res = this ->render_TRACE (r);
149+ }
150+ else if (method == MHD_HTTP_METHOD_OPTIONS)
151+ {
152+ res = this ->render_OPTIONS (r);
153+ }
154+ else if (method == MHD_HTTP_METHOD_CONNECT)
155+ {
156+ res = this ->render_CONNECT (r);
157+ }
158+ else
159+ {
160+ res = this ->render (r);
161+ }
162+ }
163+ else
156164 {
157- res = this ->render (r );
165+ res = this ->render_405 ( );
158166 }
159167 return res;
160168}
0 commit comments