src/server/proxy/httpclient.h

changeset 675
edacba8beedb
parent 673
144bdc33fdb6
equal deleted inserted replaced
674:6a031133a498 675:edacba8beedb
35 #include <sys/socket.h> 35 #include <sys/socket.h>
36 #include <cx/string.h> 36 #include <cx/string.h>
37 #include <cx/mempool.h> 37 #include <cx/mempool.h>
38 #include <cx/test.h> 38 #include <cx/test.h>
39 39
40 #include <inttypes.h>
41
40 #ifdef __cplusplus 42 #ifdef __cplusplus
41 extern "C" { 43 extern "C" {
42 #endif 44 #endif
43 45
44 #define HTTP_CLIENT_BUFFER_SIZE 4096 46 #define HTTP_CLIENT_BUFFER_SIZE 4096
59 int socketfd; 61 int socketfd;
60 62
61 HeaderArray *request_headers; 63 HeaderArray *request_headers;
62 HeaderArray *response_headers; 64 HeaderArray *response_headers;
63 65
66 /*
67 * request content length
68 * 0: no request body
69 * > 0: request body with static length
70 * -1: request body with chunked transfer encoding
71 */
72 int64_t req_content_length;
73
64 int error; 74 int error;
65 int statuscode; 75 int statuscode;
66 76
67 /* 77 /*
68 * Request body callback function 78 * Request body callback function
69 * 79 *
70 * size_t request_body_read(HttpClient *client, void *buf, size_t size, void *userdata) 80 * ssize_t request_body_read(HttpClient *client, void *buf, size_t size, void *userdata)
81 *
82 * Return: number of processed bytes,
83 * HTTP_CLIENT_CALLBACK_WOULD_BLOCK or HTTP_CLIENT_CALLBACK_ERROR.
71 */ 84 */
72 // TODO: fix, doesn't work this way 85 ssize_t (*request_body_read)(HttpClient *, void *, size_t, void *);
73 //size_t (*request_body_read)(HttpClient *, void *, size_t, void *); 86 void *request_body_read_userdata;
74 //void *request_body_read_userdata;
75 87
76 /* 88 /*
77 * Response start callback function 89 * Response start callback function
78 * 90 *
79 * int response_start(HttpClient *client, int status, char *message, void *userdata) 91 * int response_start(HttpClient *client, int status, char *message, void *userdata)
107 // internals 119 // internals
108 HttpParser *parser; 120 HttpParser *parser;
109 netbuf buffer; 121 netbuf buffer;
110 122
111 char *req_buffer; 123 char *req_buffer;
124 size_t req_buffer_alloc;
112 size_t req_buffer_len; 125 size_t req_buffer_len;
113 size_t req_buffer_pos; 126 size_t req_buffer_pos;
127 size_t req_contentlength_pos;
114 128
129 int request_body_complete;
115 int header_complete; 130 int header_complete;
116 131
117 Event readev; 132 Event readev;
118 Event writeev; 133 Event writeev;
119 }; 134 };
146 * This functions creates a copy of name/value and the original pointers can be 161 * This functions creates a copy of name/value and the original pointers can be
147 * discarded after the function returns. 162 * discarded after the function returns.
148 */ 163 */
149 int http_client_add_request_header_copy(HttpClient *client, cxstring name, cxstring value); 164 int http_client_add_request_header_copy(HttpClient *client, cxstring name, cxstring value);
150 165
166 /*
167 * Sets the content length for the request body
168 */
169 int http_client_set_content_length(HttpClient *client, int64_t contentlength);
170
171 /*
172 * Enables a request body with a chunked transfer encoding
173 */
174 int http_client_enable_chunked_transfer_encoding(HttpClient *client);
175
151 int http_client_start(HttpClient *client); 176 int http_client_start(HttpClient *client);
152 177
153 178
154 void http_client_add_tests(CxTestSuite *suite); 179 void http_client_add_tests(CxTestSuite *suite);
155 180

mercurial