aboutsummaryrefslogtreecommitdiff
path: root/src/examples/fileserver_example.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2015-06-26 21:18:13 +0000
committerChristian Grothoff <christian@grothoff.org>2015-06-26 21:18:13 +0000
commit62f06f739ab45dc1b8d5a46c5a3060b641573e6e (patch)
treeb3dae68820b2d48e6563fac78338b466a64bd059 /src/examples/fileserver_example.c
parent2d02ec7e60727d45de7f6e675fc8b03844f8c6c3 (diff)
downloadlibmicrohttpd-62f06f739ab45dc1b8d5a46c5a3060b641573e6e.tar.gz
libmicrohttpd-62f06f739ab45dc1b8d5a46c5a3060b641573e6e.zip
-support HEAD in example
Diffstat (limited to 'src/examples/fileserver_example.c')
-rw-r--r--src/examples/fileserver_example.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/src/examples/fileserver_example.c b/src/examples/fileserver_example.c
index 8f5223ab..e18ae747 100644
--- a/src/examples/fileserver_example.c
+++ b/src/examples/fileserver_example.c
@@ -16,7 +16,6 @@
16 License along with this library; if not, write to the Free Software 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 17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18*/ 18*/
19
20/** 19/**
21 * @file fileserver_example.c 20 * @file fileserver_example.c
22 * @brief minimal example for how to use libmicrohttpd to serve files 21 * @brief minimal example for how to use libmicrohttpd to serve files
@@ -29,8 +28,12 @@
29 28
30#define PAGE "<html><head><title>File not found</title></head><body>File not found</body></html>" 29#define PAGE "<html><head><title>File not found</title></head><body>File not found</body></html>"
31 30
31
32static ssize_t 32static ssize_t
33file_reader (void *cls, uint64_t pos, char *buf, size_t max) 33file_reader (void *cls,
34 uint64_t pos,
35 char *buf,
36 size_t max)
34{ 37{
35 FILE *file = cls; 38 FILE *file = cls;
36 39
@@ -38,6 +41,7 @@ file_reader (void *cls, uint64_t pos, char *buf, size_t max)
38 return fread (buf, 1, max, file); 41 return fread (buf, 1, max, file);
39} 42}
40 43
44
41static void 45static void
42free_callback (void *cls) 46free_callback (void *cls)
43{ 47{
@@ -45,6 +49,7 @@ free_callback (void *cls)
45 fclose (file); 49 fclose (file);
46} 50}
47 51
52
48static int 53static int
49ahc_echo (void *cls, 54ahc_echo (void *cls,
50 struct MHD_Connection *connection, 55 struct MHD_Connection *connection,
@@ -60,7 +65,8 @@ ahc_echo (void *cls,
60 FILE *file; 65 FILE *file;
61 struct stat buf; 66 struct stat buf;
62 67
63 if (0 != strcmp (method, MHD_HTTP_METHOD_GET)) 68 if ( (0 != strcmp (method, MHD_HTTP_METHOD_GET)) &&
69 (0 != strcmp (method, MHD_HTTP_METHOD_HEAD)) )
64 return MHD_NO; /* unexpected method */ 70 return MHD_NO; /* unexpected method */
65 if (&aptr != *ptr) 71 if (&aptr != *ptr)
66 { 72 {
@@ -73,7 +79,7 @@ ahc_echo (void *cls,
73 file = fopen (&url[1], "rb"); 79 file = fopen (&url[1], "rb");
74 else 80 else
75 file = NULL; 81 file = NULL;
76 if (file == NULL) 82 if (NULL == file)
77 { 83 {
78 response = MHD_create_response_from_buffer (strlen (PAGE), 84 response = MHD_create_response_from_buffer (strlen (PAGE),
79 (void *) PAGE, 85 (void *) PAGE,
@@ -87,7 +93,7 @@ ahc_echo (void *cls,
87 &file_reader, 93 &file_reader,
88 file, 94 file,
89 &free_callback); 95 &free_callback);
90 if (response == NULL) 96 if (NULL == response)
91 { 97 {
92 fclose (file); 98 fclose (file);
93 return MHD_NO; 99 return MHD_NO;
@@ -98,6 +104,7 @@ ahc_echo (void *cls,
98 return ret; 104 return ret;
99} 105}
100 106
107
101int 108int
102main (int argc, char *const *argv) 109main (int argc, char *const *argv)
103{ 110{