Coverage Report

Created: 2024-11-20 15:53

/root/doris/be/src/http/http_status.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_status.h"
19
20
#include <map>
21
#include <string>
22
#include <utility>
23
24
namespace doris {
25
26
static std::map<HttpStatus, std::string> s_reason_map = {
27
        {HttpStatus::CONTINUE, "Continue"},
28
        {HttpStatus::SWITCHING_PROTOCOLS, "Switching Protocols"},
29
        {HttpStatus::OK, "OK"},
30
        {HttpStatus::CREATED, "Created"},
31
        {HttpStatus::ACCEPTED, "Accepted"},
32
        {HttpStatus::NON_AUTHORITATIVE_INFORMATION, "Non-Authoritative Information"},
33
        {HttpStatus::NO_CONTENT, "No Content"},
34
        {HttpStatus::RESET_CONTENT, "Reset Content"},
35
        {HttpStatus::PARTIAL_CONTENT, "Partial Content"},
36
        {HttpStatus::MULTIPLE_CHOICES, "Multiple Choices"},
37
        {HttpStatus::MOVED_PERMANENTLY, "Moved Permanently"},
38
        {HttpStatus::FOUND, "Found"},
39
        {HttpStatus::SEE_OTHER, "See Other"},
40
        {HttpStatus::NOT_MODIFIED, "Not Modified"},
41
        {HttpStatus::USE_PROXY, "Use Proxy"},
42
        {HttpStatus::TEMPORARY_REDIRECT, "Temporary Redirect"},
43
        {HttpStatus::BAD_REQUEST, "Bad Request"},
44
        {HttpStatus::UNAUTHORIZED, "Unauthorized"},
45
        {HttpStatus::PAYMENT_REQUIRED, "Payment Required"},
46
        {HttpStatus::FORBIDDEN, "Forbidden"},
47
        {HttpStatus::NOT_FOUND, "Not Found"},
48
        {HttpStatus::METHOD_NOT_ALLOWED, "Method Not Allowed"},
49
        {HttpStatus::NOT_ACCEPTABLE, "Not Acceptable"},
50
        {HttpStatus::PROXY_AUTHENTICATION, "Proxy Authentication Required"},
51
        {HttpStatus::REQUEST_TIMEOUT, "Request Time-out"},
52
        {HttpStatus::CONFLICT, "Conflict"},
53
        {HttpStatus::GONE, "Gone"},
54
        {HttpStatus::LENGTH_REQUIRED, "Length Required"},
55
        {HttpStatus::PRECONDITION_FAILED, "Precondition Failed"},
56
        {HttpStatus::REQUEST_ENTITY_TOO_LARGE, "Request Entity Too Large"},
57
        {HttpStatus::REQUEST_URI_TOO_LONG, "Request-URI Too Large"},
58
        {HttpStatus::UNSUPPORTED_MEDIA_TYPE, "Unsupported Media Type"},
59
        {HttpStatus::REQUESTED_RANGE_NOT_SATISFIED, "Requested range not satisfiable"},
60
        {HttpStatus::EXPECTATION_FAILED, "Expectation Failed"},
61
        {HttpStatus::INTERNAL_SERVER_ERROR, "Internal Server Error"},
62
        {HttpStatus::NOT_IMPLEMENTED, "Not Implemented"},
63
        {HttpStatus::BAD_GATEWAY, "Bad Gateway"},
64
        {HttpStatus::SERVICE_UNAVAILABLE, "Service Unavailable"},
65
        {HttpStatus::GATEWAY_TIMEOUT, "Gateway Time-out"},
66
        {HttpStatus::HTTP_VERSION_NOT_SUPPORTED, "HTTP Version not supported"}};
67
68
22
std::string default_reason(const HttpStatus& status) {
69
22
    auto iter = s_reason_map.find(status);
70
22
    if (iter != s_reason_map.end()) {
71
22
        return iter->second;
72
22
    }
73
0
    return "No reason";
74
22
}
75
76
0
std::string to_code(const HttpStatus& status) {
77
0
    return std::to_string(status);
78
0
}
79
80
} // namespace doris