libmicrohttpd

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

commit 0b23a93cb22c5e1af1a3bfbf76aeae974bacfeaf
parent a90ce65429da20ab34b10623a3c05d3431b3147f
Author: Christian Grothoff <christian@grothoff.org>
Date:   Sun, 13 Jun 2010 09:05:57 +0000

better

Diffstat:
Msrc/examples/https_fileserver_example.c | 12++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/src/examples/https_fileserver_example.c b/src/examples/https_fileserver_example.c @@ -131,7 +131,11 @@ http_ahc (void *cls, } *ptr = NULL; /* reset when done */ - file = fopen (&url[1], "rb"); + if ( (0 == stat (url, &buf)) && + (S_ISREG (buf.st_mode)) ) + file = fopen (&url[1], "rb"); + else + file = NULL; if (file == NULL) { response = MHD_create_response_from_data (strlen (EMPTY_PAGE), @@ -142,11 +146,15 @@ http_ahc (void *cls, } else { - stat (url, &buf); response = MHD_create_response_from_callback (buf.st_size, 32 * 1024, /* 32k PAGE_NOT_FOUND size */ &file_reader, file, (MHD_ContentReaderFreeCallback) & fclose); + if (response == NULL) + { + fclose (file); + return MHD_NO; + } ret = MHD_queue_response (connection, MHD_HTTP_OK, response); MHD_destroy_response (response); }