From da5a2bfe0571fbee3378f730633c17efcac94c30 Mon Sep 17 00:00:00 2001 From: José Bollo Date: Fri, 18 Mar 2016 14:53:10 +0100 Subject: http-svc: fix bug of uninitialized response MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I98dd53d6994e11d674916546173875196732aabc Signed-off-by: José Bollo --- src/http-svc.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/http-svc.c b/src/http-svc.c index 3dcd2f5d..5d7303fc 100644 --- a/src/http-svc.c +++ b/src/http-svc.c @@ -85,7 +85,7 @@ STATIC void computeEtag(char *etag, size_t maxlen, struct stat *sbuf) { STATIC int servFile (struct MHD_Connection *connection, AFB_session *session, const char *url, AFB_staticfile *staticfile) { const char *etagCache, *mimetype; char etagValue[15]; - struct MHD_Response *response = NULL; + struct MHD_Response *response; struct stat sbuf; if (fstat (staticfile->fd, &sbuf) != 0) { @@ -139,14 +139,13 @@ STATIC int servFile (struct MHD_Connection *connection, AFB_session *session, co MHD_queue_response(connection, MHD_HTTP_NOT_MODIFIED, response); } else { // it's a new file, we need to upload it to client + response = MHD_create_response_from_fd(sbuf.st_size, staticfile->fd); // if we have magic let's try to guest mime type if (session->magic) { mimetype= magic_descriptor(session->magic, staticfile->fd); if (mimetype != NULL) MHD_add_response_header (response, MHD_HTTP_HEADER_CONTENT_TYPE, mimetype); } else mimetype="application/unknown"; - if (verbose) fprintf(stderr, "Serving: [%s] mime=%s\n", staticfile->path, mimetype); - response = MHD_create_response_from_fd(sbuf.st_size, staticfile->fd); MHD_add_response_header(response, MHD_HTTP_HEADER_CACHE_CONTROL, session->cacheTimeout); // default one hour cache MHD_add_response_header(response, MHD_HTTP_HEADER_ETAG, etagValue); MHD_queue_response(connection, MHD_HTTP_OK, response); -- cgit 1.2.3-korg