libmicrohttpd

HTTP/1.x server C library (MHD 1.x, stable)
Log | Files | Refs | Submodules | README | LICENSE

commit 62f06f739ab45dc1b8d5a46c5a3060b641573e6e
parent 2d02ec7e60727d45de7f6e675fc8b03844f8c6c3
Author: Christian Grothoff <christian@grothoff.org>
Date:   Fri, 26 Jun 2015 21:18:13 +0000

-support HEAD in example

Diffstat:
Msrc/examples/fileserver_example.c | 17++++++++++++-----
1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/src/examples/fileserver_example.c b/src/examples/fileserver_example.c @@ -16,7 +16,6 @@ License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ - /** * @file fileserver_example.c * @brief minimal example for how to use libmicrohttpd to serve files @@ -29,8 +28,12 @@ #define PAGE "<html><head><title>File not found</title></head><body>File not found</body></html>" + static ssize_t -file_reader (void *cls, uint64_t pos, char *buf, size_t max) +file_reader (void *cls, + uint64_t pos, + char *buf, + size_t max) { FILE *file = cls; @@ -38,6 +41,7 @@ file_reader (void *cls, uint64_t pos, char *buf, size_t max) return fread (buf, 1, max, file); } + static void free_callback (void *cls) { @@ -45,6 +49,7 @@ free_callback (void *cls) fclose (file); } + static int ahc_echo (void *cls, struct MHD_Connection *connection, @@ -60,7 +65,8 @@ ahc_echo (void *cls, FILE *file; struct stat buf; - if (0 != strcmp (method, MHD_HTTP_METHOD_GET)) + if ( (0 != strcmp (method, MHD_HTTP_METHOD_GET)) && + (0 != strcmp (method, MHD_HTTP_METHOD_HEAD)) ) return MHD_NO; /* unexpected method */ if (&aptr != *ptr) { @@ -73,7 +79,7 @@ ahc_echo (void *cls, file = fopen (&url[1], "rb"); else file = NULL; - if (file == NULL) + if (NULL == file) { response = MHD_create_response_from_buffer (strlen (PAGE), (void *) PAGE, @@ -87,7 +93,7 @@ ahc_echo (void *cls, &file_reader, file, &free_callback); - if (response == NULL) + if (NULL == response) { fclose (file); return MHD_NO; @@ -98,6 +104,7 @@ ahc_echo (void *cls, return ret; } + int main (int argc, char *const *argv) {