@@ -10,7 +10,13 @@ extern "C"
1010#include " ../common/HTTPS.h"
1111#include " ../common/config.h"
1212
13- static std::set<std::string> validMethod {" GET" , " HEAD" , " POST" , " PUT" , " DELETE" , " PATCH" };
13+ static std::string validMethod[] = {" GET" , " HEAD" , " POST" , " PUT" , " DELETE" , " PATCH" };
14+
15+ static int str_toupper (char c)
16+ {
17+ unsigned char uc = (unsigned char ) c;
18+ return toupper (uc);
19+ }
1420
1521static std::string w_checkstring (lua_State *L, int idx)
1622{
@@ -41,13 +47,15 @@ static void w_readheaders(lua_State *L, int idx, HTTPSClient::header_map &header
4147
4248static std::string w_optmethod (lua_State *L, int idx, const std::string &defaultMethod)
4349{
50+ std::string *const validMethodEnd = validMethod + sizeof (validMethod) / sizeof (std::string);
51+
4452 if (lua_isnoneornil (L, idx))
4553 return defaultMethod;
4654
4755 std::string str = w_checkstring (L, idx);
48- std::transform (str.begin (), str.end (), str.begin (), []( unsigned char c) { return toupper (c); } );
56+ std::transform (str.begin (), str.end (), str.begin (), str_toupper );
4957
50- if (validMethod. find (str) == validMethod. end () )
58+ if (std:: find (validMethod, validMethodEnd, str) == validMethodEnd )
5159 luaL_argerror (L, idx, " expected one of \" get\" , \" head\" , \" post\" , \" put\" , \" delete\" , or \" patch\" " );
5260
5361 return str;
0 commit comments