diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/examples/Makefile.am | 70 | ||||
-rw-r--r-- | src/examples/chunked_example.c | 94 | ||||
-rw-r--r-- | src/include/microhttpd.h | 2 | ||||
-rw-r--r-- | src/microhttpd/connection.c | 11 | ||||
-rw-r--r-- | src/testcurl/test_get.c | 20 |
5 files changed, 150 insertions, 47 deletions
diff --git a/src/examples/Makefile.am b/src/examples/Makefile.am index fbd1920d..9146c3a1 100644 --- a/src/examples/Makefile.am +++ b/src/examples/Makefile.am | |||
@@ -16,7 +16,7 @@ if ENABLE_SPDY | |||
16 | spdyex = \ | 16 | spdyex = \ |
17 | spdy_event_loop \ | 17 | spdy_event_loop \ |
18 | spdy_fileserver \ | 18 | spdy_fileserver \ |
19 | spdy_response_with_callback | 19 | spdy_response_with_callback |
20 | 20 | ||
21 | if HAVE_SPDYLAY | 21 | if HAVE_SPDYLAY |
22 | spdyex += mhd2spdy | 22 | spdyex += mhd2spdy |
@@ -28,6 +28,7 @@ endif | |||
28 | noinst_PROGRAMS = \ | 28 | noinst_PROGRAMS = \ |
29 | benchmark \ | 29 | benchmark \ |
30 | benchmark_https \ | 30 | benchmark_https \ |
31 | chunked_example \ | ||
31 | minimal_example \ | 32 | minimal_example \ |
32 | dual_stack_example \ | 33 | dual_stack_example \ |
33 | minimal_example_comet \ | 34 | minimal_example_comet \ |
@@ -40,7 +41,7 @@ noinst_PROGRAMS = \ | |||
40 | 41 | ||
41 | 42 | ||
42 | if ENABLE_HTTPS | 43 | if ENABLE_HTTPS |
43 | noinst_PROGRAMS += https_fileserver_example | 44 | noinst_PROGRAMS += https_fileserver_example |
44 | endif | 45 | endif |
45 | if HAVE_POSTPROCESSOR | 46 | if HAVE_POSTPROCESSOR |
46 | noinst_PROGRAMS += \ | 47 | noinst_PROGRAMS += \ |
@@ -53,12 +54,12 @@ endif | |||
53 | 54 | ||
54 | if ENABLE_DAUTH | 55 | if ENABLE_DAUTH |
55 | noinst_PROGRAMS += \ | 56 | noinst_PROGRAMS += \ |
56 | digest_auth_example | 57 | digest_auth_example |
57 | endif | 58 | endif |
58 | 59 | ||
59 | if ENABLE_BAUTH | 60 | if ENABLE_BAUTH |
60 | noinst_PROGRAMS += \ | 61 | noinst_PROGRAMS += \ |
61 | authorization_example | 62 | authorization_example |
62 | endif | 63 | endif |
63 | 64 | ||
64 | if HAVE_W32 | 65 | if HAVE_W32 |
@@ -66,9 +67,14 @@ AM_CFLAGS += -DWINDOWS | |||
66 | endif | 67 | endif |
67 | 68 | ||
68 | minimal_example_SOURCES = \ | 69 | minimal_example_SOURCES = \ |
69 | minimal_example.c | 70 | minimal_example.c |
70 | minimal_example_LDADD = \ | 71 | minimal_example_LDADD = \ |
71 | $(top_builddir)/src/microhttpd/libmicrohttpd.la | 72 | $(top_builddir)/src/microhttpd/libmicrohttpd.la |
73 | |||
74 | chunked_example_SOURCES = \ | ||
75 | chunked_example.c | ||
76 | chunked_example_LDADD = \ | ||
77 | $(top_builddir)/src/microhttpd/libmicrohttpd.la | ||
72 | 78 | ||
73 | demo_SOURCES = \ | 79 | demo_SOURCES = \ |
74 | demo.c | 80 | demo.c |
@@ -90,68 +96,68 @@ mhd2spdy_LDADD = \ | |||
90 | -lssl -lcrypto -lspdylay | 96 | -lssl -lcrypto -lspdylay |
91 | 97 | ||
92 | benchmark_SOURCES = \ | 98 | benchmark_SOURCES = \ |
93 | benchmark.c | 99 | benchmark.c |
94 | benchmark_CPPFLAGS = \ | 100 | benchmark_CPPFLAGS = \ |
95 | $(AM_CPPFLAGS) $(CPU_COUNT_DEF) | 101 | $(AM_CPPFLAGS) $(CPU_COUNT_DEF) |
96 | benchmark_LDADD = \ | 102 | benchmark_LDADD = \ |
97 | $(top_builddir)/src/microhttpd/libmicrohttpd.la | 103 | $(top_builddir)/src/microhttpd/libmicrohttpd.la |
98 | 104 | ||
99 | benchmark_https_SOURCES = \ | 105 | benchmark_https_SOURCES = \ |
100 | benchmark_https.c | 106 | benchmark_https.c |
101 | benchmark_https_CPPFLAGS = \ | 107 | benchmark_https_CPPFLAGS = \ |
102 | $(AM_CPPFLAGS) $(CPU_COUNT_DEF) | 108 | $(AM_CPPFLAGS) $(CPU_COUNT_DEF) |
103 | benchmark_https_LDADD = \ | 109 | benchmark_https_LDADD = \ |
104 | $(top_builddir)/src/microhttpd/libmicrohttpd.la | 110 | $(top_builddir)/src/microhttpd/libmicrohttpd.la |
105 | 111 | ||
106 | dual_stack_example_SOURCES = \ | 112 | dual_stack_example_SOURCES = \ |
107 | dual_stack_example.c | 113 | dual_stack_example.c |
108 | dual_stack_example_LDADD = \ | 114 | dual_stack_example_LDADD = \ |
109 | $(top_builddir)/src/microhttpd/libmicrohttpd.la | 115 | $(top_builddir)/src/microhttpd/libmicrohttpd.la |
110 | 116 | ||
111 | post_example_SOURCES = \ | 117 | post_example_SOURCES = \ |
112 | post_example.c | 118 | post_example.c |
113 | post_example_LDADD = \ | 119 | post_example_LDADD = \ |
114 | $(top_builddir)/src/microhttpd/libmicrohttpd.la | 120 | $(top_builddir)/src/microhttpd/libmicrohttpd.la |
115 | 121 | ||
116 | minimal_example_comet_SOURCES = \ | 122 | minimal_example_comet_SOURCES = \ |
117 | minimal_example_comet.c | 123 | minimal_example_comet.c |
118 | minimal_example_comet_LDADD = \ | 124 | minimal_example_comet_LDADD = \ |
119 | $(top_builddir)/src/microhttpd/libmicrohttpd.la | 125 | $(top_builddir)/src/microhttpd/libmicrohttpd.la |
120 | 126 | ||
121 | authorization_example_SOURCES = \ | 127 | authorization_example_SOURCES = \ |
122 | authorization_example.c | 128 | authorization_example.c |
123 | authorization_example_LDADD = \ | 129 | authorization_example_LDADD = \ |
124 | $(top_builddir)/src/microhttpd/libmicrohttpd.la | 130 | $(top_builddir)/src/microhttpd/libmicrohttpd.la |
125 | 131 | ||
126 | digest_auth_example_SOURCES = \ | 132 | digest_auth_example_SOURCES = \ |
127 | digest_auth_example.c | 133 | digest_auth_example.c |
128 | digest_auth_example_LDADD = \ | 134 | digest_auth_example_LDADD = \ |
129 | $(top_builddir)/src/microhttpd/libmicrohttpd.la | 135 | $(top_builddir)/src/microhttpd/libmicrohttpd.la |
130 | 136 | ||
131 | refuse_post_example_SOURCES = \ | 137 | refuse_post_example_SOURCES = \ |
132 | refuse_post_example.c | 138 | refuse_post_example.c |
133 | refuse_post_example_LDADD = \ | 139 | refuse_post_example_LDADD = \ |
134 | $(top_builddir)/src/microhttpd/libmicrohttpd.la | 140 | $(top_builddir)/src/microhttpd/libmicrohttpd.la |
135 | 141 | ||
136 | querystring_example_SOURCES = \ | 142 | querystring_example_SOURCES = \ |
137 | querystring_example.c | 143 | querystring_example.c |
138 | querystring_example_LDADD = \ | 144 | querystring_example_LDADD = \ |
139 | $(top_builddir)/src/microhttpd/libmicrohttpd.la | 145 | $(top_builddir)/src/microhttpd/libmicrohttpd.la |
140 | 146 | ||
141 | fileserver_example_SOURCES = \ | 147 | fileserver_example_SOURCES = \ |
142 | fileserver_example.c | 148 | fileserver_example.c |
143 | fileserver_example_LDADD = \ | 149 | fileserver_example_LDADD = \ |
144 | $(top_builddir)/src/microhttpd/libmicrohttpd.la | 150 | $(top_builddir)/src/microhttpd/libmicrohttpd.la |
145 | 151 | ||
146 | fileserver_example_dirs_SOURCES = \ | 152 | fileserver_example_dirs_SOURCES = \ |
147 | fileserver_example_dirs.c | 153 | fileserver_example_dirs.c |
148 | fileserver_example_dirs_LDADD = \ | 154 | fileserver_example_dirs_LDADD = \ |
149 | $(top_builddir)/src/microhttpd/libmicrohttpd.la | 155 | $(top_builddir)/src/microhttpd/libmicrohttpd.la |
150 | 156 | ||
151 | fileserver_example_external_select_SOURCES = \ | 157 | fileserver_example_external_select_SOURCES = \ |
152 | fileserver_example_external_select.c | 158 | fileserver_example_external_select.c |
153 | fileserver_example_external_select_LDADD = \ | 159 | fileserver_example_external_select_LDADD = \ |
154 | $(top_builddir)/src/microhttpd/libmicrohttpd.la | 160 | $(top_builddir)/src/microhttpd/libmicrohttpd.la |
155 | 161 | ||
156 | https_fileserver_example_SOURCES = \ | 162 | https_fileserver_example_SOURCES = \ |
157 | https_fileserver_example.c | 163 | https_fileserver_example.c |
@@ -162,19 +168,19 @@ https_fileserver_example_LDADD = \ | |||
162 | 168 | ||
163 | 169 | ||
164 | spdy_event_loop_SOURCES = \ | 170 | spdy_event_loop_SOURCES = \ |
165 | spdy_event_loop.c | 171 | spdy_event_loop.c |
166 | spdy_event_loop_LDADD = \ | 172 | spdy_event_loop_LDADD = \ |
167 | $(top_builddir)/src/microspdy/libmicrospdy.la \ | 173 | $(top_builddir)/src/microspdy/libmicrospdy.la \ |
168 | -lz | 174 | -lz |
169 | 175 | ||
170 | spdy_fileserver_SOURCES = \ | 176 | spdy_fileserver_SOURCES = \ |
171 | spdy_fileserver.c | 177 | spdy_fileserver.c |
172 | spdy_fileserver_LDADD = \ | 178 | spdy_fileserver_LDADD = \ |
173 | $(top_builddir)/src/microspdy/libmicrospdy.la \ | 179 | $(top_builddir)/src/microspdy/libmicrospdy.la \ |
174 | -lz | 180 | -lz |
175 | 181 | ||
176 | spdy_response_with_callback_SOURCES = \ | 182 | spdy_response_with_callback_SOURCES = \ |
177 | spdy_response_with_callback.c | 183 | spdy_response_with_callback.c |
178 | spdy_response_with_callback_LDADD = \ | 184 | spdy_response_with_callback_LDADD = \ |
179 | $(top_builddir)/src/microspdy/libmicrospdy.la \ | 185 | $(top_builddir)/src/microspdy/libmicrospdy.la \ |
180 | -lz | 186 | -lz |
diff --git a/src/examples/chunked_example.c b/src/examples/chunked_example.c new file mode 100644 index 00000000..eb054e4b --- /dev/null +++ b/src/examples/chunked_example.c | |||
@@ -0,0 +1,94 @@ | |||
1 | /* | ||
2 | This file is part of libmicrohttpd | ||
3 | (C) 2015 Christian Grothoff (and other contributing authors) | ||
4 | |||
5 | This library is free software; you can redistribute it and/or | ||
6 | modify it under the terms of the GNU Lesser General Public | ||
7 | License as published by the Free Software Foundation; either | ||
8 | version 2.1 of the License, or (at your option) any later version. | ||
9 | |||
10 | This library is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Lesser General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Lesser General Public | ||
16 | License along with this library; if not, write to the Free Software | ||
17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
18 | */ | ||
19 | /** | ||
20 | * @file chunked_example.c | ||
21 | * @brief example for generating chunked encoding with libmicrohttpd | ||
22 | * @author Christian Grothoff | ||
23 | */ | ||
24 | |||
25 | #include "platform.h" | ||
26 | #include <microhttpd.h> | ||
27 | |||
28 | |||
29 | static ssize_t | ||
30 | callback (void *cls, | ||
31 | uint64_t pos, | ||
32 | char *buf, | ||
33 | size_t max) | ||
34 | { | ||
35 | return MHD_CONTENT_READER_END_OF_STREAM; | ||
36 | } | ||
37 | |||
38 | |||
39 | |||
40 | static int | ||
41 | ahc_echo (void *cls, | ||
42 | struct MHD_Connection *connection, | ||
43 | const char *url, | ||
44 | const char *method, | ||
45 | const char *version, | ||
46 | const char *upload_data, size_t *upload_data_size, void **ptr) | ||
47 | { | ||
48 | static int aptr; | ||
49 | struct MHD_Response *response; | ||
50 | int ret; | ||
51 | |||
52 | if (0 != strcmp (method, "GET")) | ||
53 | return MHD_NO; /* unexpected method */ | ||
54 | if (&aptr != *ptr) | ||
55 | { | ||
56 | /* do never respond on first call */ | ||
57 | *ptr = &aptr; | ||
58 | return MHD_YES; | ||
59 | } | ||
60 | *ptr = NULL; /* reset when done */ | ||
61 | response = MHD_create_response_from_callback (MHD_SIZE_UNKNOWN, | ||
62 | 1024, | ||
63 | &callback, | ||
64 | NULL, | ||
65 | NULL); | ||
66 | ret = MHD_queue_response (connection, MHD_HTTP_OK, response); | ||
67 | MHD_destroy_response (response); | ||
68 | return ret; | ||
69 | } | ||
70 | |||
71 | int | ||
72 | main (int argc, char *const *argv) | ||
73 | { | ||
74 | struct MHD_Daemon *d; | ||
75 | |||
76 | if (argc != 2) | ||
77 | { | ||
78 | printf ("%s PORT\n", argv[0]); | ||
79 | return 1; | ||
80 | } | ||
81 | d = MHD_start_daemon (// MHD_USE_SELECT_INTERNALLY | MHD_USE_DEBUG | MHD_USE_POLL, | ||
82 | MHD_USE_SELECT_INTERNALLY | MHD_USE_DEBUG, | ||
83 | // MHD_USE_THREAD_PER_CONNECTION | MHD_USE_DEBUG | MHD_USE_POLL, | ||
84 | // MHD_USE_THREAD_PER_CONNECTION | MHD_USE_DEBUG, | ||
85 | atoi (argv[1]), | ||
86 | NULL, NULL, &ahc_echo, NULL, | ||
87 | MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 120, | ||
88 | MHD_OPTION_END); | ||
89 | if (d == NULL) | ||
90 | return 1; | ||
91 | (void) getc (stdin); | ||
92 | MHD_stop_daemon (d); | ||
93 | return 0; | ||
94 | } | ||
diff --git a/src/include/microhttpd.h b/src/include/microhttpd.h index e1b41d66..65664daa 100644 --- a/src/include/microhttpd.h +++ b/src/include/microhttpd.h | |||
@@ -130,7 +130,7 @@ typedef intptr_t ssize_t; | |||
130 | * Current version of the library. | 130 | * Current version of the library. |
131 | * 0x01093001 = 1.9.30-1. | 131 | * 0x01093001 = 1.9.30-1. |
132 | */ | 132 | */ |
133 | #define MHD_VERSION 0x00093901 | 133 | #define MHD_VERSION 0x00093902 |
134 | 134 | ||
135 | /** | 135 | /** |
136 | * MHD-internal return code for "YES". | 136 | * MHD-internal return code for "YES". |
diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c index 87951736..b54567f1 100644 --- a/src/microhttpd/connection.c +++ b/src/microhttpd/connection.c | |||
@@ -741,7 +741,9 @@ build_header_response (struct MHD_Connection *connection) | |||
741 | close the connection */ | 741 | close the connection */ |
742 | /* 'close' header doesn't exist yet, see if we need to add one; | 742 | /* 'close' header doesn't exist yet, see if we need to add one; |
743 | if the client asked for a close, no need to start chunk'ing */ | 743 | if the client asked for a close, no need to start chunk'ing */ |
744 | if (MHD_YES == keepalive_possible (connection)) | 744 | if ( (MHD_YES == keepalive_possible (connection)) && |
745 | (MHD_str_equal_caseless_ (MHD_HTTP_VERSION_1_1, | ||
746 | connection->version) ) ) | ||
745 | { | 747 | { |
746 | have_encoding = MHD_get_response_header (connection->response, | 748 | have_encoding = MHD_get_response_header (connection->response, |
747 | MHD_HTTP_HEADER_TRANSFER_ENCODING); | 749 | MHD_HTTP_HEADER_TRANSFER_ENCODING); |
@@ -762,7 +764,8 @@ build_header_response (struct MHD_Connection *connection) | |||
762 | } | 764 | } |
763 | else | 765 | else |
764 | { | 766 | { |
765 | /* Keep alive not possible => set close header if not present */ | 767 | /* Keep alive or chunking not possible |
768 | => set close header if not present */ | ||
766 | if (NULL == response_has_close) | 769 | if (NULL == response_has_close) |
767 | must_add_close = MHD_YES; | 770 | must_add_close = MHD_YES; |
768 | } | 771 | } |
@@ -782,8 +785,8 @@ build_header_response (struct MHD_Connection *connection) | |||
782 | if ( (MHD_SIZE_UNKNOWN != connection->response->total_size) && | 785 | if ( (MHD_SIZE_UNKNOWN != connection->response->total_size) && |
783 | (NULL == have_content_length) && | 786 | (NULL == have_content_length) && |
784 | ( (NULL == connection->method) || | 787 | ( (NULL == connection->method) || |
785 | (!MHD_str_equal_caseless_ (connection->method, | 788 | (! MHD_str_equal_caseless_ (connection->method, |
786 | MHD_HTTP_METHOD_CONNECT)) ) ) | 789 | MHD_HTTP_METHOD_CONNECT)) ) ) |
787 | { | 790 | { |
788 | /* | 791 | /* |
789 | Here we add a content-length if one is missing; however, | 792 | Here we add a content-length if one is missing; however, |
diff --git a/src/testcurl/test_get.c b/src/testcurl/test_get.c index c7821b21..df70893e 100644 --- a/src/testcurl/test_get.c +++ b/src/testcurl/test_get.c | |||
@@ -19,7 +19,7 @@ | |||
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file daemontest_get.c | 22 | * @file test_get.c |
23 | * @brief Testcase for libmicrohttpd GET operations | 23 | * @brief Testcase for libmicrohttpd GET operations |
24 | * TODO: test parsing of query | 24 | * TODO: test parsing of query |
25 | * @author Christian Grothoff | 25 | * @author Christian Grothoff |
@@ -271,7 +271,7 @@ testExternalGet () | |||
271 | fd_set ws; | 271 | fd_set ws; |
272 | fd_set es; | 272 | fd_set es; |
273 | MHD_socket max; | 273 | MHD_socket max; |
274 | int running; | 274 | int running; |
275 | struct CURLMsg *msg; | 275 | struct CURLMsg *msg; |
276 | time_t start; | 276 | time_t start; |
277 | struct timeval tv; | 277 | struct timeval tv; |
@@ -461,41 +461,41 @@ testStopRace (int poll_flag) | |||
461 | struct sockaddr_in sin; | 461 | struct sockaddr_in sin; |
462 | MHD_socket fd; | 462 | MHD_socket fd; |
463 | struct MHD_Daemon *d; | 463 | struct MHD_Daemon *d; |
464 | 464 | ||
465 | d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_DEBUG | poll_flag, | 465 | d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_DEBUG | poll_flag, |
466 | 1081, NULL, NULL, &ahc_echo, "GET", | 466 | 1081, NULL, NULL, &ahc_echo, "GET", |
467 | MHD_OPTION_CONNECTION_TIMEOUT, 5, MHD_OPTION_END); | 467 | MHD_OPTION_CONNECTION_TIMEOUT, 5, MHD_OPTION_END); |
468 | if (d == NULL) | 468 | if (d == NULL) |
469 | return 16; | 469 | return 16; |
470 | 470 | ||
471 | fd = socket (PF_INET, SOCK_STREAM, 0); | 471 | fd = socket (PF_INET, SOCK_STREAM, 0); |
472 | if (fd == MHD_INVALID_SOCKET) | 472 | if (fd == MHD_INVALID_SOCKET) |
473 | { | 473 | { |
474 | fprintf(stderr, "socket error\n"); | 474 | fprintf(stderr, "socket error\n"); |
475 | return 256; | 475 | return 256; |
476 | } | 476 | } |
477 | 477 | ||
478 | memset(&sin, 0, sizeof(sin)); | 478 | memset(&sin, 0, sizeof(sin)); |
479 | sin.sin_family = AF_INET; | 479 | sin.sin_family = AF_INET; |
480 | sin.sin_port = htons(1081); | 480 | sin.sin_port = htons(1081); |
481 | sin.sin_addr.s_addr = htonl(0x7f000001); | 481 | sin.sin_addr.s_addr = htonl(0x7f000001); |
482 | 482 | ||
483 | if (connect (fd, (struct sockaddr *)(&sin), sizeof(sin)) < 0) | 483 | if (connect (fd, (struct sockaddr *)(&sin), sizeof(sin)) < 0) |
484 | { | 484 | { |
485 | fprintf(stderr, "connect error\n"); | 485 | fprintf(stderr, "connect error\n"); |
486 | MHD_socket_close_ (fd); | 486 | MHD_socket_close_ (fd); |
487 | return 512; | 487 | return 512; |
488 | } | 488 | } |
489 | 489 | ||
490 | /* printf("Waiting\n"); */ | 490 | /* printf("Waiting\n"); */ |
491 | /* Let the thread get going. */ | 491 | /* Let the thread get going. */ |
492 | usleep(500000); | 492 | usleep(500000); |
493 | 493 | ||
494 | /* printf("Stopping daemon\n"); */ | 494 | /* printf("Stopping daemon\n"); */ |
495 | MHD_stop_daemon (d); | 495 | MHD_stop_daemon (d); |
496 | 496 | ||
497 | MHD_socket_close_ (fd); | 497 | MHD_socket_close_ (fd); |
498 | 498 | ||
499 | /* printf("good\n"); */ | 499 | /* printf("good\n"); */ |
500 | return 0; | 500 | return 0; |
501 | } | 501 | } |