Annotation of parser3/src/include/pa_http.h, revision 1.27
1.1 paf 1: /** @file
2: Parser: commonly used functions.
3:
1.19 moko 4: Copyright (c) 2001-2017 Art. Lebedev Studio (http://www.artlebedev.com)
1.1 paf 5: Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
6: */
7:
8: #ifndef PA_HTTP_H
9: #define PA_HTTP_H
10:
1.27 ! moko 11: #define IDENT_PA_HTTP_H "$Id: pa_http.h,v 1.26 2020/10/14 11:24:46 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.1 paf 23: #ifndef DOXYGEN
24: struct File_read_http_result {
25: char *str; size_t length;
26: HashStringValue* headers;
27: };
28: #endif
29:
1.21 moko 30: class HTTP_Headers {
1.15 moko 31: public:
32: class Header {
33: public:
34: String::Body name;
35: String::Body value;
36:
37: Header(String::Body aname, String::Body avalue) : name(aname), value(avalue) {}
38:
39: void transcode(Charset &charset, Charset &source){
40: name=Charset::transcode(name, charset, source);
41: value=Charset::transcode(value, charset, source);
42: }
43:
44: };
45:
46: Array<Header> headers;
47:
48: String::Body content_type;
1.18 moko 49: uint64_t content_length;
1.15 moko 50:
1.21 moko 51: HTTP_Headers() : content_type(""), content_length(0){}
1.15 moko 52:
1.18 moko 53: bool add_header(const char *line);
1.15 moko 54:
1.17 moko 55: void clear(){
56: headers.clear();
57: content_type="";
1.18 moko 58: content_length=0;
1.17 moko 59: }
60:
1.15 moko 61: };
62:
1.20 moko 63: /*** http part ***/
64:
1.9 misha 65: Table* parse_cookies(Request& r, Table *cookies);
1.16 moko 66: void tables_update(HashStringValue& tables, const String::Body name, const String& value);
1.9 misha 67:
1.6 moko 68: char *pa_http_safe_header_name(const char *name);
69:
1.15 moko 70: 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 71:
1.20 moko 72: /*** httpd part ***/
73:
74: class HTTPD_request;
75:
76: class HTTPD_Connection : public PA_Allocated {
77: public:
78: int sock;
79: const char *remote_addr;
80: HTTPD_request *request;
81:
1.26 moko 82: HTTPD_Connection() : sock(-1), remote_addr(NULL), request(NULL){}
83: ~HTTPD_Connection();
1.20 moko 84:
1.21 moko 85: Array<HTTP_Headers::Header> &headers();
1.20 moko 86:
87: const char *method();
88: const char *uri();
89: const char *content_type();
90: uint64_t content_length();
91:
1.22 moko 92: const char *query(){
93: if(uri()){
94: const char *result=strchr(uri(), '?');
95: if(result++ && *result)
96: return result;
97: }
98: return NULL;
99: }
100:
1.26 moko 101: bool accept(int, int);
1.20 moko 102: void read_header();
103: size_t read_post(char *, size_t);
1.24 moko 104: size_t send_body(const void *, size_t);
1.20 moko 105: };
106:
107: class HTTPD_Server : public PA_Allocated {
108: public:
1.27 ! moko 109: enum HTTPD_MODE {
! 110: SEQUENTIAL,
! 111: PARALLEL,
! 112: MULTITHREADED
! 113: } static mode;
! 114:
1.26 moko 115: static int bind(const char *);
1.20 moko 116: };
117:
1.1 paf 118: #endif
E-mail: