• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2013 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "net/http/http_status_code.h"
6 
7 #include <ostream>
8 
9 #include "base/notreached.h"
10 
11 namespace net {
12 
GetHttpReasonPhrase(HttpStatusCode code)13 const char* GetHttpReasonPhrase(HttpStatusCode code) {
14   if (const char* phrase = TryToGetHttpReasonPhrase(code)) {
15     return phrase;
16   }
17   DUMP_WILL_BE_NOTREACHED() << "unknown HTTP status code " << code;
18   return nullptr;
19 }
20 
TryToGetHttpReasonPhrase(HttpStatusCode code)21 const char* TryToGetHttpReasonPhrase(HttpStatusCode code) {
22   switch (code) {
23 #define HTTP_STATUS_ENUM_VALUE(label, code, reason) \
24   case HTTP_##label:                                \
25     return reason;
26 #include "net/http/http_status_code_list.h"
27 #undef HTTP_STATUS_ENUM_VALUE
28 
29     default:
30       return nullptr;
31   }
32 }
33 
TryToGetHttpStatusCode(int response_code)34 const std::optional<HttpStatusCode> TryToGetHttpStatusCode(int response_code) {
35   switch (response_code) {
36 #define HTTP_STATUS_ENUM_VALUE(label, code, reason) \
37   case code:                                        \
38     return HTTP_##label;
39 #include "net/http/http_status_code_list.h"
40 #undef HTTP_STATUS_ENUM_VALUE
41 
42     default:
43       return std::nullopt;
44   }
45 }
46 
47 }  // namespace net
48