| 102 | } |
| 103 | |
| 104 | bool Str2HttpMethod(const char* method_str, HttpMethod* method) { |
| 105 | const char fc = ::toupper(*method_str); |
| 106 | if (fc == 'G') { |
| 107 | if (strcasecmp(method_str + 1, /*G*/"ET") == 0) { |
| 108 | *method = HTTP_METHOD_GET; |
| 109 | return true; |
| 110 | } |
| 111 | } else if (fc == 'P') { |
| 112 | if (strcasecmp(method_str + 1, /*P*/"OST") == 0) { |
| 113 | *method = HTTP_METHOD_POST; |
| 114 | return true; |
| 115 | } else if (strcasecmp(method_str + 1, /*P*/"UT") == 0) { |
| 116 | *method = HTTP_METHOD_PUT; |
| 117 | return true; |
| 118 | } |
| 119 | } |
| 120 | pthread_once(&g_init_maps_once, BuildHttpMethodMaps); |
| 121 | if (fc < 'A' || fc > 'Z') { |
| 122 | return false; |
| 123 | } |
| 124 | size_t index = g_first_char_index[fc - 'A']; |
| 125 | if (index == 0) { |
| 126 | return false; |
| 127 | } |
| 128 | --index; |
| 129 | for (; index < ARRAY_SIZE(g_method_pairs); ++index) { |
| 130 | const HttpMethodPair& p = g_method_pairs[index]; |
| 131 | if (strcasecmp(method_str, p.str) == 0) { |
| 132 | *method = p.method; |
| 133 | return true; |
| 134 | } |
| 135 | if (p.str[0] != fc) { |
| 136 | return false; |
| 137 | } |
| 138 | } |
| 139 | return false; |
| 140 | } |
| 141 | |
| 142 | } // namespace brpc |