--- parser3/src/main/pa_http.C 2020/12/17 11:50:44 1.112 +++ parser3/src/main/pa_http.C 2020/12/20 19:58:54 1.115 @@ -14,7 +14,7 @@ #include "pa_vfile.h" #include "pa_random.h" -volatile const char * IDENT_PA_HTTP_C="$Id: pa_http.C,v 1.112 2020/12/17 11:50:44 moko Exp $" IDENT_PA_HTTP_H; +volatile const char * IDENT_PA_HTTP_C="$Id: pa_http.C,v 1.115 2020/12/20 19:58:54 moko Exp $" IDENT_PA_HTTP_H; #ifdef _MSC_VER #include @@ -1061,6 +1061,20 @@ ssize_t HTTPD_request::pa_recv(int sockf } } +static bool valid_http_method(const char * method){ + return method && ( + !strcmp(method, "GET") || + !strcmp(method, "HEAD") || + !strcmp(method, "POST") || + !strcmp(method, "PUT") || + !strcmp(method, "DELETE") || + !strcmp(method, "CONNECT") || + !strcmp(method, "OPTIONS") || + !strcmp(method, "TRACE") || + !strcmp(method, "PATCH") + ); +} + bool HTTPD_request::read_header(int sock) { enum HTTPD_request_state state = HTTPD_METHOD; @@ -1077,14 +1091,7 @@ bool HTTPD_request::read_header(int sock char *method_line = pa_strdup(buf, method_size); method = extract_method(method_line); - if(!method || - strcmp(method, "GET") && - strcmp(method, "HEAD") && - strcmp(method, "POST") && - strcmp(method, "PUT") && - strcmp(method, "DELETE") && - strcmp(method, "PATCH") - ) + if(!valid_http_method(method)) throw Exception("httpd.method", new String(method ? method : method_line), "invalid request method"); state = HTTPD_HEADERS; } @@ -1224,10 +1231,13 @@ bool HTTPD_Connection::accept(int server } HTTPD_Server::HTTPD_MODE HTTPD_Server::mode = HTTPD_Server::SEQUENTIAL; +const char *HTTPD_Server::port=NULL; void HTTPD_Server::set_mode(const String &value){ if(value == "sequental") mode = SEQUENTIAL; +#ifdef HAVE_TLS else if (value == "threaded") mode = MULTITHREADED; +#endif #ifdef _MSC_VER else throw Exception("httpd.mode", &value, "$main:HTTPD.mode must be 'sequental' or 'threaded'"); #else @@ -1239,10 +1249,11 @@ void HTTPD_Server::set_mode(const String int HTTPD_Server::bind(const char *host_port){ struct sockaddr_in me; - const char *port = strchr(host_port, ':'); + port = strchr(host_port, ':'); const char *host = NULL; - if(port && port > host_port){ - host = pa_strdup(host_port, port - host_port); + if(port ){ + if(port > host_port) + host = pa_strdup(host_port, port - host_port); port += 1; } else { port = host_port;