--- parser3/src/main/pa_http.C 2020/10/12 21:15:07 1.89 +++ parser3/src/main/pa_http.C 2020/10/14 00:07:42 1.92 @@ -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.89 2020/10/12 21:15:07 moko Exp $" IDENT_PA_HTTP_H; +volatile const char * IDENT_PA_HTTP_C="$Id: pa_http.C,v 1.92 2020/10/14 00:07:42 moko Exp $" IDENT_PA_HTTP_H; #ifdef _MSC_VER #include @@ -968,7 +968,14 @@ void 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")) + if(!method || + strcmp(method, "GET") && + strcmp(method, "HEAD") && + strcmp(method, "POST") && + strcmp(method, "PUT") && + strcmp(method, "DELETE") && + strcmp(method, "PATCH") + ) throw Exception("httpd.method", new String(method ? method : method_line), "invalid request method"); state = HTTPD_HEADERS; } @@ -1037,10 +1044,22 @@ void HTTPD_Connection::read_header(){ request->read_header(sock); } +void HTTPD_Connection::close(){ + ::closesocket(sock); +} + size_t HTTPD_Connection::read_post(char *body, size_t max_bytes) { return request->read_post(sock, body, max_bytes); } +size_t HTTPD_Connection::send_body(const void *buf, size_t size) { + if(send(sock, (const char*)buf, size, 0) != (ssize_t)size) { + int no=pa_socks_errno(); + throw Exception("httpd.timeout", 0, "error sending response: %s (%d)", pa_socks_strerr(no), no); + } + return size; +} + static int sock_on = 1; int HTTPD_Server::bind(const char *host_port){