Annotation of parser3/src/include/pa_http.h, revision 1.21
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.21 ! moko 11: #define IDENT_PA_HTTP_H "$Id: pa_http.h,v 1.20 2020/10/10 06:08:36 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:
82: HTTPD_Connection(int asock, const char *addr) : sock(asock), remote_addr(addr), request(NULL){};
83:
1.21 ! moko 84: Array<HTTP_Headers::Header> &headers();
1.20 moko 85:
86: const char *method();
87: const char *uri();
88: const char *content_type();
89: uint64_t content_length();
90:
91: void read_header();
92: size_t read_post(char *, size_t);
93: size_t send_body(const void *buf, size_t size);
94: };
95:
96: class HTTPD_Server : public PA_Allocated {
97: public:
98: static int bind(const char *host, int port);
99: static HTTPD_Connection *accept(int sock, int timeout_value);
100: };
101:
1.1 paf 102: #endif
E-mail: