2 * Copyright (C) 2016-2019 "IoT.bzh"
3 * Author: José Bollo <jose.bollo@iot.bzh>
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 #if WITH_LIBMICROHTTPD
20 #include <microhttpd.h>
22 #include "afb-method.h"
24 enum afb_method get_method(const char *method)
26 switch (method[0] & ~' ') {
28 return afb_method_connect;
30 return afb_method_delete;
32 return afb_method_get;
34 return afb_method_head;
36 return afb_method_options;
38 switch (method[1] & ~' ') {
40 return afb_method_patch;
42 return afb_method_post;
44 return afb_method_put;
48 return afb_method_trace;
50 return afb_method_none;
53 #if !defined(MHD_HTTP_METHOD_PATCH)
54 #define MHD_HTTP_METHOD_PATCH "PATCH"
56 const char *get_method_name(enum afb_method method)
60 return MHD_HTTP_METHOD_GET;
62 return MHD_HTTP_METHOD_POST;
64 return MHD_HTTP_METHOD_HEAD;
65 case afb_method_connect:
66 return MHD_HTTP_METHOD_CONNECT;
67 case afb_method_delete:
68 return MHD_HTTP_METHOD_DELETE;
69 case afb_method_options:
70 return MHD_HTTP_METHOD_OPTIONS;
71 case afb_method_patch:
72 return MHD_HTTP_METHOD_PATCH;
74 return MHD_HTTP_METHOD_PUT;
75 case afb_method_trace:
76 return MHD_HTTP_METHOD_TRACE;