--- parser3/src/include/pa_http.h 2017/01/23 09:33:02 1.18 +++ parser3/src/include/pa_http.h 2020/10/14 11:24:46 1.26 @@ -1,14 +1,14 @@ /** @file Parser: commonly used functions. - Copyright (c) 2001-2015 Art. Lebedev Studio (http://www.artlebedev.com) + Copyright (c) 2001-2017 Art. Lebedev Studio (http://www.artlebedev.com) Author: Alexandr Petrosian (http://paf.design.ru) */ #ifndef PA_HTTP_H #define PA_HTTP_H -#define IDENT_PA_HTTP_H "$Id: pa_http.h,v 1.18 2017/01/23 09:33:02 moko Exp $" +#define IDENT_PA_HTTP_H "$Id: pa_http.h,v 1.26 2020/10/14 11:24:46 moko Exp $" #include "pa_vstring.h" #include "pa_vint.h" @@ -27,7 +27,7 @@ struct File_read_http_result { }; #endif -class ResponseHeaders { +class HTTP_Headers { public: class Header { public: @@ -48,7 +48,7 @@ public: String::Body content_type; uint64_t content_length; - ResponseHeaders() : content_type(""), content_length(0){} + HTTP_Headers() : content_type(""), content_length(0){} bool add_header(const char *line); @@ -60,6 +60,8 @@ public: }; +/*** http part ***/ + Table* parse_cookies(Request& r, Table *cookies); void tables_update(HashStringValue& tables, const String::Body name, const String& value); @@ -67,4 +69,44 @@ char *pa_http_safe_header_name(const cha File_read_http_result pa_internal_file_read_http(Request& r, const String& file_spec, bool as_text, HashStringValue *options=0, bool transcode_text_result=true); +/*** httpd part ***/ + +class HTTPD_request; + +class HTTPD_Connection : public PA_Allocated { +public: + int sock; + const char *remote_addr; + HTTPD_request *request; + + HTTPD_Connection() : sock(-1), remote_addr(NULL), request(NULL){} + ~HTTPD_Connection(); + + Array &headers(); + + const char *method(); + const char *uri(); + const char *content_type(); + uint64_t content_length(); + + const char *query(){ + if(uri()){ + const char *result=strchr(uri(), '?'); + if(result++ && *result) + return result; + } + return NULL; + } + + bool accept(int, int); + void read_header(); + size_t read_post(char *, size_t); + size_t send_body(const void *, size_t); +}; + +class HTTPD_Server : public PA_Allocated { +public: + static int bind(const char *); +}; + #endif