diff options
author | Christian Grothoff <christian@grothoff.org> | 2007-07-09 05:50:23 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2007-07-09 05:50:23 +0000 |
commit | 98f89b072fe81041aa996eb388ca64f6d57f56cc (patch) | |
tree | 4429b013987d3e21bd3d361069f3a4b36cebb40e | |
parent | 2a85058539eef04393603379a11f6ce6d940866a (diff) | |
download | libmicrohttpd-98f89b072fe81041aa996eb388ca64f6d57f56cc.tar.gz libmicrohttpd-98f89b072fe81041aa996eb388ca64f6d57f56cc.zip |
headers
-rw-r--r-- | README | 1 | ||||
-rw-r--r-- | src/daemon/connection.c | 18 | ||||
-rw-r--r-- | src/include/microhttpd.h | 94 |
3 files changed, 95 insertions, 18 deletions
@@ -8,6 +8,7 @@ before certain features can be used at all: | |||
8 | For POST: | 8 | For POST: |
9 | ========= | 9 | ========= |
10 | - Decoding of POST data, testing thereof | 10 | - Decoding of POST data, testing thereof |
11 | - POST testcase currently fails (blocks!) | ||
11 | 12 | ||
12 | For http-compliance: | 13 | For http-compliance: |
13 | ==================== | 14 | ==================== |
diff --git a/src/daemon/connection.c b/src/daemon/connection.c index 5de459ed..fa6450be 100644 --- a/src/daemon/connection.c +++ b/src/daemon/connection.c | |||
@@ -458,13 +458,14 @@ MHD_parse_connection_headers(struct MHD_Connection * connection) { | |||
458 | connection->headersReceived = 1; | 458 | connection->headersReceived = 1; |
459 | clen = MHD_lookup_connection_value(connection, | 459 | clen = MHD_lookup_connection_value(connection, |
460 | MHD_HEADER_KIND, | 460 | MHD_HEADER_KIND, |
461 | "Content-Length"); | 461 | MHD_HTTP_HEADER_CONTENT_LENGTH); |
462 | if (clen != NULL) { | 462 | if (clen != NULL) { |
463 | if (1 != sscanf(clen, | 463 | if (1 != sscanf(clen, |
464 | "%llu", | 464 | "%llu", |
465 | &cval)) { | 465 | &cval)) { |
466 | MHD_DLOG(connection->daemon, | 466 | MHD_DLOG(connection->daemon, |
467 | "Failed to parse Content-Length header `%s', closing connection.\n", | 467 | "Failed to parse `%s' header `%s', closing connection.\n", |
468 | MHD_HTTP_HEADER_CONTENT_LENGTH, | ||
468 | clen); | 469 | clen); |
469 | goto DIE; | 470 | goto DIE; |
470 | } | 471 | } |
@@ -472,8 +473,8 @@ MHD_parse_connection_headers(struct MHD_Connection * connection) { | |||
472 | connection->bodyReceived = cval == 0 ? 1 : 0; | 473 | connection->bodyReceived = cval == 0 ? 1 : 0; |
473 | } else { | 474 | } else { |
474 | if (NULL == MHD_lookup_connection_value(connection, | 475 | if (NULL == MHD_lookup_connection_value(connection, |
475 | MHD_HEADER_KIND, | 476 | MHD_HEADER_KIND, |
476 | "Transfer-Encoding")) { | 477 | MHD_HTTP_HEADER_TRANSFER_ENCODING)) { |
477 | /* this request does not have a body */ | 478 | /* this request does not have a body */ |
478 | connection->uploadSize = 0; | 479 | connection->uploadSize = 0; |
479 | connection->bodyReceived = 1; | 480 | connection->bodyReceived = 1; |
@@ -660,13 +661,13 @@ MHD_add_extra_headers(struct MHD_Connection * connection) { | |||
660 | "Connection", | 661 | "Connection", |
661 | "close"); | 662 | "close"); |
662 | } else if (NULL == MHD_get_response_header(connection->response, | 663 | } else if (NULL == MHD_get_response_header(connection->response, |
663 | "Content-Length")) { | 664 | MHD_HTTP_HEADER_CONTENT_LENGTH)) { |
664 | _REAL_SNPRINTF(buf, | 665 | _REAL_SNPRINTF(buf, |
665 | 128, | 666 | 128, |
666 | "%llu", | 667 | "%llu", |
667 | (unsigned long long) connection->response->total_size); | 668 | (unsigned long long) connection->response->total_size); |
668 | MHD_add_response_header(connection->response, | 669 | MHD_add_response_header(connection->response, |
669 | "Content-Length", | 670 | MHD_HTTP_HEADER_CONTENT_LENGTH, |
670 | buf); | 671 | buf); |
671 | } | 672 | } |
672 | } | 673 | } |
@@ -686,7 +687,8 @@ MHD_build_header_response(struct MHD_Connection * connection) { | |||
686 | 687 | ||
687 | MHD_add_extra_headers(connection); | 688 | MHD_add_extra_headers(connection); |
688 | SPRINTF(code, | 689 | SPRINTF(code, |
689 | "HTTP/1.1 %u\r\n", | 690 | "%s %u\r\n", |
691 | MHD_HTTP_VERSION_1_1, | ||
690 | connection->responseCode); | 692 | connection->responseCode); |
691 | off = strlen(code); | 693 | off = strlen(code); |
692 | /* estimate size */ | 694 | /* estimate size */ |
@@ -841,7 +843,7 @@ MHD_connection_handle_write(struct MHD_Connection * connection) { | |||
841 | connection->write_buffer = NULL; | 843 | connection->write_buffer = NULL; |
842 | connection->write_buffer_size = 0; | 844 | connection->write_buffer_size = 0; |
843 | if ( (connection->read_close != 0) || | 845 | if ( (connection->read_close != 0) || |
844 | (0 != strcasecmp("HTTP/1.1", | 846 | (0 != strcasecmp(MHD_HTTP_VERSION_1_1, |
845 | connection->version)) ) { | 847 | connection->version)) ) { |
846 | /* closed for reading => close for good! */ | 848 | /* closed for reading => close for good! */ |
847 | CLOSE(connection->socket_fd); | 849 | CLOSE(connection->socket_fd); |
diff --git a/src/include/microhttpd.h b/src/include/microhttpd.h index ae918b4a..01f31ca2 100644 --- a/src/include/microhttpd.h +++ b/src/include/microhttpd.h | |||
@@ -26,21 +26,18 @@ | |||
26 | * | 26 | * |
27 | * All symbols defined in this header start with MHD. MHD is a | 27 | * All symbols defined in this header start with MHD. MHD is a |
28 | * micro-httpd library. As such, it does not have any API for logging | 28 | * micro-httpd library. As such, it does not have any API for logging |
29 | * errors.<p> | 29 | * errors. Also, it may not support all of the HTTP features directly, |
30 | * where applicable, portions of HTTP may have to be handled by | ||
31 | * clients of the library (the library is supposed to handle | ||
32 | * everything that it must handle, such as basic connection | ||
33 | * management; however, detailed interpretations of headers | ||
34 | * and methods are left to clients).<p> | ||
30 | * | 35 | * |
31 | * All functions are guaranteed to be completely reentrant and | 36 | * All functions are guaranteed to be completely reentrant and |
32 | * thread-safe.<p> | 37 | * thread-safe.<p> |
33 | * | 38 | * |
34 | * TODO: | 39 | * TODO: |
35 | * - proper API for file uploads via HTTP | 40 | * - Add option codes for buffer sizes and SSL support |
36 | * - We probably need a significantly more extensive API for | ||
37 | * proper SSL support (set local certificate, etc.) | ||
38 | * | ||
39 | * | ||
40 | * | ||
41 | * Students are encouraged to add additional HTTP status codes to this | ||
42 | * file, but should not change anything else. If you think something | ||
43 | * needs to be changed, talk to your instructor first. | ||
44 | */ | 41 | */ |
45 | 42 | ||
46 | #ifndef MHD_MICROHTTPD_H | 43 | #ifndef MHD_MICROHTTPD_H |
@@ -61,12 +58,21 @@ extern "C" { | |||
61 | #endif | 58 | #endif |
62 | #endif | 59 | #endif |
63 | 60 | ||
61 | /** | ||
62 | * Current version of the library. | ||
63 | */ | ||
64 | #define MHD_VERSION 0x00000000 | 64 | #define MHD_VERSION 0x00000000 |
65 | 65 | ||
66 | /** | ||
67 | * MHD-internal return codes. | ||
68 | */ | ||
66 | #define MHD_YES 1 | 69 | #define MHD_YES 1 |
67 | 70 | ||
68 | #define MHD_NO 0 | 71 | #define MHD_NO 0 |
69 | 72 | ||
73 | /** | ||
74 | * HTTP response codes. | ||
75 | */ | ||
70 | #define MHD_HTTP_CONTINUE 100 | 76 | #define MHD_HTTP_CONTINUE 100 |
71 | #define MHD_HTTP_SWITCHING_PROTOCOLS 101 | 77 | #define MHD_HTTP_SWITCHING_PROTOCOLS 101 |
72 | #define MHD_HTTP_PROCESSING 102 | 78 | #define MHD_HTTP_PROCESSING 102 |
@@ -125,6 +131,62 @@ extern "C" { | |||
125 | #define MHD_HTTP_BANDWIDTH_LIMIT_EXCEEDED 509 | 131 | #define MHD_HTTP_BANDWIDTH_LIMIT_EXCEEDED 509 |
126 | #define MHD_HTTP_NOT_EXTENDED 510 | 132 | #define MHD_HTTP_NOT_EXTENDED 510 |
127 | 133 | ||
134 | /* See also: http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html */ | ||
135 | #define MHD_HTTP_HEADER_ACCEPT "Accept" | ||
136 | #define MHD_HTTP_HEADER_ACCEPT_CHARSET "Accept-Charset" | ||
137 | #define MHD_HTTP_HEADER_ACCEPT_ENCODING "Accept-Encoding" | ||
138 | #define MHD_HTTP_HEADER_ACCEPT_LANGUAGE "Accept-Language" | ||
139 | #define MHD_HTTP_HEADER_ACCEPT_RANGES "Accept-Ranges" | ||
140 | #define MHD_HTTP_HEADER_AGE "Age" | ||
141 | #define MHD_HTTP_HEADER_ALLOW "Allow" | ||
142 | #define MHD_HTTP_HEADER_AUTHORIZATION "Authorization" | ||
143 | #define MHD_HTTP_HEADER_CACHE_CONTROL "Cache-Control" | ||
144 | #define MHD_HTTP_HEADER_CONNECTION "Connection" | ||
145 | #define MHD_HTTP_HEADER_CONTENT_ENCODING "Content-Encoding" | ||
146 | #define MHD_HTTP_HEADER_CONTENT_LANGUAGE "Content-Language" | ||
147 | #define MHD_HTTP_HEADER_CONTENT_LENGTH "Content-Length" | ||
148 | #define MHD_HTTP_HEADER_CONTENT_LOCATION "Content-Location" | ||
149 | #define MHD_HTTP_HEADER_CONTENT_MD5 "Content-MD5" | ||
150 | #define MHD_HTTP_HEADER_CONTENT_RANGE "Content-Range" | ||
151 | #define MHD_HTTP_HEADER_CONTENT_TYPE "Content-Type" | ||
152 | #define MHD_HTTP_HEADER_DATE "Date" | ||
153 | #define MHD_HTTP_HEADER_ETAG "ETag" | ||
154 | #define MHD_HTTP_HEADER_EXPECT "Expect" | ||
155 | #define MHD_HTTP_HEADER_EXPIRES "Expires" | ||
156 | #define MHD_HTTP_HEADER_FROM "From" | ||
157 | #define MHD_HTTP_HEADER_HOST "Host" | ||
158 | #define MHD_HTTP_HEADER_IF_MATCH "If-Match" | ||
159 | #define MHD_HTTP_HEADER_IF_MODIFIED_SINCE "If-Modified-Since" | ||
160 | #define MHD_HTTP_HEADER_IF_NONE_MATCH "If-None-Match" | ||
161 | #define MHD_HTTP_HEADER_IF_RANGE "If-Range" | ||
162 | #define MHD_HTTP_HEADER_IF_UNMODIFIED_SINCE "If-Unmodified-Since" | ||
163 | #define MHD_HTTP_HEADER_LAST_MODIFIED "Last-Modified" | ||
164 | #define MHD_HTTP_HEADER_LOCATION "Location" | ||
165 | #define MHD_HTTP_HEADER_MAX_FORWARDS "Max-Forwards" | ||
166 | #define MHD_HTTP_HEADER_PRAGMA "Pragma" | ||
167 | #define MHD_HTTP_HEADER_PROXY_AUTHENTICATE "Proxy-Authenticate" | ||
168 | #define MHD_HTTP_HEADER_PROXY_AUTHORIZATION "Proxy-Authorization" | ||
169 | #define MHD_HTTP_HEADER_RANGE "Range" | ||
170 | #define MHD_HTTP_HEADER_REFERER "Referer" | ||
171 | #define MHD_HTTP_HEADER_RETRY_AFTER "Retry-After" | ||
172 | #define MHD_HTTP_HEADER_SERVER "Server" | ||
173 | #define MHD_HTTP_HEADER_TE "TE" | ||
174 | #define MHD_HTTP_HEADER_TRAILER "Trailer" | ||
175 | #define MHD_HTTP_HEADER_TRANSFER_ENCODING "Transfer-Encoding" | ||
176 | #define MHD_HTTP_HEADER_UPGRADE "Upgrade" | ||
177 | #define MHD_HTTP_HEADER_USER_AGENT "User-Agent" | ||
178 | #define MHD_HTTP_HEADER_VARY "Vary" | ||
179 | #define MHD_HTTP_HEADER_VIA "Via" | ||
180 | #define MHD_HTTP_HEADER_WARNING "Warning" | ||
181 | #define MHD_HTTP_HEADER_WWW_AUTHENTICATE "WWW-Authenticate" | ||
182 | |||
183 | /** | ||
184 | * HTTP versions (used to match against the first line of the | ||
185 | * HTTP header as well as in the response code). | ||
186 | */ | ||
187 | #define MHD_HTTP_VERSION_1_0 "HTTP/1.0" | ||
188 | #define MHD_HTTP_VERSION_1_1 "HTTP/1.1" | ||
189 | |||
128 | 190 | ||
129 | 191 | ||
130 | /** | 192 | /** |
@@ -224,10 +286,22 @@ enum MHD_ValueKind { | |||
224 | 286 | ||
225 | }; | 287 | }; |
226 | 288 | ||
289 | /** | ||
290 | * Handle for the daemon (listening on a socket for HTTP traffic). | ||
291 | */ | ||
227 | struct MHD_Daemon; | 292 | struct MHD_Daemon; |
228 | 293 | ||
294 | /** | ||
295 | * Handle for a connection / HTTP request. With HTTP/1.1, multiple | ||
296 | * requests can be run over the same connection. However, MHD will | ||
297 | * only show one request per TCP connection to the client at any given | ||
298 | * time. | ||
299 | */ | ||
229 | struct MHD_Connection; | 300 | struct MHD_Connection; |
230 | 301 | ||
302 | /** | ||
303 | * Handle for a response. | ||
304 | */ | ||
231 | struct MHD_Response; | 305 | struct MHD_Response; |
232 | 306 | ||
233 | /** | 307 | /** |