Annotation of parser3/src/include/pa_http.h, revision 1.39
1.1 paf 1: /** @file
2: Parser: commonly used functions.
3:
1.37 moko 4: Copyright (c) 2001-2026 Art. Lebedev Studio (https://www.artlebedev.com)
1.34 moko 5: Authors: Konstantin Morshnev <moko@design.ru>, Alexandr Petrosian <paf@design.ru>
1.1 paf 6: */
7:
8: #ifndef PA_HTTP_H
9: #define PA_HTTP_H
10:
1.39 ! moko 11: #define IDENT_PA_HTTP_H "$Id: pa_http.h,v 1.38 2026/10/14 00:32:44 moko Exp $"
1.1 paf 12:
13: #include "pa_vstring.h"
14: #include "pa_vint.h"
15: #include "pa_vhash.h"
16: #include "pa_vtable.h"
17: #include "pa_socks.h"
1.15 moko 18: #include "pa_charset.h"
1.10 misha 19: #include "pa_request.h"
1.1 paf 20:
1.11 misha 21: #define HTTP_COOKIES_NAME "cookies"
1.12 moko 22:
1.33 moko 23: #ifdef _MSC_VER
24: #include <windows.h>
25: #endif
26:
1.1 paf 27: #ifndef DOXYGEN
28: struct File_read_http_result {
29: char *str; size_t length;
30: HashStringValue* headers;
31: };
32: #endif
33:
1.21 moko 34: class HTTP_Headers {
1.15 moko 35: public:
36: class Header {
37: public:
38: String::Body name;
39: String::Body value;
40:
41: Header(String::Body aname, String::Body avalue) : name(aname), value(avalue) {}
42:
43: void transcode(Charset &charset, Charset &source){
44: name=Charset::transcode(name, charset, source);
45: value=Charset::transcode(value, charset, source);
46: }
47:
48: };
49:
50: Array<Header> headers;
51:
52: String::Body content_type;
1.18 moko 53: uint64_t content_length;
1.15 moko 54:
1.21 moko 55: HTTP_Headers() : content_type(""), content_length(0){}
1.15 moko 56:
1.18 moko 57: bool add_header(const char *line);
1.15 moko 58:
1.17 moko 59: void clear(){
60: headers.clear();
1.36 moko 61: content_type.clear();
1.18 moko 62: content_length=0;
1.17 moko 63: }
64:
1.15 moko 65: };
66:
1.20 moko 67: /*** http part ***/
68:
1.9 misha 69: Table* parse_cookies(Request& r, Table *cookies);
1.16 moko 70: void tables_update(HashStringValue& tables, const String::Body name, const String& value);
1.9 misha 71:
1.6 moko 72: char *pa_http_safe_header_name(const char *name);
73:
1.15 moko 74: 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);
1.1 paf 75:
1.20 moko 76: /*** httpd part ***/
77:
1.31 moko 78: //#define HTTPD_DEBUG
79:
1.20 moko 80: class HTTPD_request;
81:
82: class HTTPD_Connection : public PA_Allocated {
83: public:
1.33 moko 84: SOCKET sock;
1.20 moko 85: const char *remote_addr;
86: HTTPD_request *request;
87:
1.33 moko 88: HTTPD_Connection() : sock(INVALID_SOCKET), remote_addr(NULL), request(NULL){}
1.26 moko 89: ~HTTPD_Connection();
1.20 moko 90:
1.21 moko 91: Array<HTTP_Headers::Header> &headers();
1.20 moko 92:
93: const char *method();
94: const char *uri();
95: const char *content_type();
96: uint64_t content_length();
97:
1.22 moko 98: const char *query(){
99: if(uri()){
100: const char *result=strchr(uri(), '?');
101: if(result++ && *result)
102: return result;
103: }
104: return NULL;
105: }
106:
1.33 moko 107: bool accept(SOCKET, int);
1.30 moko 108: bool read_header();
1.20 moko 109: size_t read_post(char *, size_t);
1.24 moko 110: size_t send_body(const void *, size_t);
1.39 ! moko 111:
! 112: /// bytes received after the request headers, not processed yet
! 113: String::C unprocessed();
! 114: /// receives up to size bytes, returns 0 if the connection is closed
! 115: size_t receive(char *, size_t);
! 116: void set_nodelay();
! 117: void set_send_timeout(int timeout_secs);
1.20 moko 118: };
119:
120: class HTTPD_Server : public PA_Allocated {
121: public:
1.27 moko 122: enum HTTPD_MODE {
123: SEQUENTIAL,
124: PARALLEL,
125: MULTITHREADED
126: } static mode;
1.32 moko 127: static const char *port;
1.27 moko 128:
1.28 moko 129: static void set_mode(const String&);
1.33 moko 130: static SOCKET bind(const char *);
1.20 moko 131: };
132:
1.1 paf 133: #endif
E-mail: