summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosé Bollo <jose.bollo@iot.bzh>2016-03-18 14:53:10 +0100
committerJosé Bollo <jose.bollo@iot.bzh>2016-03-18 14:53:10 +0100
commitda5a2bfe0571fbee3378f730633c17efcac94c30 (patch)
tree0c82d2d2d75153bba1a5a2aeb5a887265ecaa85f
parent6428a6eb283cd607aa8ec3e9445963f30a783cf5 (diff)
http-svc: fix bug of uninitialized response
Change-Id: I98dd53d6994e11d674916546173875196732aabc Signed-off-by: José Bollo <jose.bollo@iot.bzh>
-rw-r--r--src/http-svc.c5
1 files 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);