src/server/proxy/httpclient.h

changeset 665
b8d5b797d090
parent 662
70fdf948b642
child 666
c99e0b352e36
equal deleted inserted replaced
664:9b1066313c17 665:b8d5b797d090
28 28
29 #ifndef PROXY_HTTPCLIENT_H 29 #ifndef PROXY_HTTPCLIENT_H
30 #define PROXY_HTTPCLIENT_H 30 #define PROXY_HTTPCLIENT_H
31 31
32 #include "../public/nsapi.h" 32 #include "../public/nsapi.h"
33 #include "../daemon/httpparser.h"
34
35 #include <sys/socket.h>
36 #include <cx/string.h>
37 #include <cx/mempool.h>
33 38
34 #ifdef __cplusplus 39 #ifdef __cplusplus
35 extern "C" { 40 extern "C" {
36 #endif 41 #endif
37 42
43 typedef struct HttpClient HttpClient;
44 struct HttpClient {
45 EventHandler *ev;
46 CxMempool *mp;
47 char *uri;
48
49 struct sockaddr *addr;
50 size_t addrlen;
51
52 HeaderArray *request_headers;
53 HeaderArray *response_headers;
54
55 /*
56 * Request body callback function
57 *
58 * size_t request_body_read(HttpClient *client, void *buf, size_t size, void *userdata)
59 */
60 // TODO: fix, doesn't work this way
61 //size_t (*request_body_read)(HttpClient *, void *, size_t, void *);
62 //void *request_body_read_userdata;
63
64 /*
65 * Response start callback function
66 *
67 * int response_start(HttpClient *client, int status, char *message, void *userdata)
68 */
69 int (*response_start)(HttpClient *, int, char *, void *);
70 void *response_start_userdata;
71
72 /*
73 * Response body write function
74 *
75 * int response_body_write(HttpClient *client, void *buf, size_t size, void *userdata)
76 */
77 int (*response_body_write)(HttpClient *, void *, size_t, void *);
78 void *response_body_write_userdata;
79
80 /*
81 * Response finished callback
82 *
83 * void response_finished(HttpClient *client, int error, void *userdata)
84 */
85 void (*response_finished)(HttpClient *, int, void *);
86 void *response_finished_userdata;
87
88
89 // internals
90
91 Event out_event;
92 Event in_event;
93 };
38 94
95 HttpClient* http_client_new(EventHandler *ev);
96
97 int http_client_set_addr(HttpClient *client, const struct sockaddr *addr, socklen_t addrlen);
98
99 /*
100 * Adds a request header
101 *
102 * This function does not create a copy of name/value. The string pointers must
103 * be valid for the lifetime of the HttpClient.
104 */
105 int http_client_add_request_header(HttpClient *client, cxmutstr name, cxmutstr value);
106
107 /*
108 * Adds a request header
109 *
110 * This functions creates a copy of name/value and the original pointers can be
111 * discarded after the function returns.
112 */
113 int http_client_add_request_header_copy(HttpClient *client, cxstring name, cxstring value);
39 114
40 115
41 #ifdef __cplusplus 116 #ifdef __cplusplus
42 } 117 }
43 #endif 118 #endif

mercurial