/root/doris/be/src/http/http_method.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | // Licensed to the Apache Software Foundation (ASF) under one |
2 | | // or more contributor license agreements. See the NOTICE file |
3 | | // distributed with this work for additional information |
4 | | // regarding copyright ownership. The ASF licenses this file |
5 | | // to you under the Apache License, Version 2.0 (the |
6 | | // "License"); you may not use this file except in compliance |
7 | | // with the License. You may obtain a copy of the License at |
8 | | // |
9 | | // http://www.apache.org/licenses/LICENSE-2.0 |
10 | | // |
11 | | // Unless required by applicable law or agreed to in writing, |
12 | | // software distributed under the License is distributed on an |
13 | | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
14 | | // KIND, either express or implied. See the License for the |
15 | | // specific language governing permissions and limitations |
16 | | // under the License. |
17 | | |
18 | | #include "http/http_method.h" |
19 | | |
20 | | #include <map> |
21 | | #include <string> |
22 | | #include <utility> |
23 | | |
24 | | namespace doris { |
25 | | |
26 | | static std::map<std::string, HttpMethod> s_method_by_desc = { |
27 | | {"GET", HttpMethod::GET}, {"PUT", HttpMethod::PUT}, |
28 | | {"POST", HttpMethod::POST}, {"HEAD", HttpMethod::HEAD}, |
29 | | {"DELETE", HttpMethod::DELETE}, {"OPTIONS", HttpMethod::OPTIONS}, |
30 | | }; |
31 | | static std::map<HttpMethod, std::string> s_desc_by_method = { |
32 | | {HttpMethod::GET, "GET"}, {HttpMethod::PUT, "PUT"}, |
33 | | {HttpMethod::POST, "POST"}, {HttpMethod::HEAD, "HEAD"}, |
34 | | {HttpMethod::DELETE, "DELETE"}, {HttpMethod::OPTIONS, "OPTIONS"}, |
35 | | }; |
36 | | |
37 | 0 | HttpMethod to_http_method(const char* desc) { |
38 | 0 | auto iter = s_method_by_desc.find(desc); |
39 | 0 | if (iter == s_method_by_desc.end()) { |
40 | 0 | return HttpMethod::UNKNOWN; |
41 | 0 | } |
42 | 0 | return iter->second; |
43 | 0 | } |
44 | | |
45 | 0 | std::string to_method_desc(const HttpMethod& method) { |
46 | 0 | auto iter = s_desc_by_method.find(method); |
47 | 0 | if (iter == s_desc_by_method.end()) { |
48 | 0 | return "UNKNOWN"; |
49 | 0 | } |
50 | 0 | return iter->second; |
51 | 0 | } |
52 | | |
53 | | } // namespace doris |