From 56f661e9c6ac6b2de998a191fade4472b2ea8313 Mon Sep 17 00:00:00 2001 From: Marko Mikulicic Date: Wed, 23 Sep 2015 11:41:15 +0100 Subject: [PATCH] Make mg send_http_file work for ESP8266 RTOS PUBLISHED_FROM=10623cfe38e143f7e107a6494baa298c788586f0 --- mongoose.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/mongoose.c b/mongoose.c index 6bae65b0..f4427bfc 100644 --- a/mongoose.c +++ b/mongoose.c @@ -4447,19 +4447,22 @@ static void mg_send_http_file2(struct mg_connection *nc, const char *path, gmt_time_string(current_time, sizeof(current_time), &t); gmt_time_string(last_modified, sizeof(last_modified), &st->st_mtime); mime_type = get_mime_type(path, "text/plain", opts); + /* + * breaking up printing in three separate mg_printf invocations + * otherwise crashes inside newlib on ESP8266. + * Not a big performance penalty on desktop. + */ mg_printf(nc, "HTTP/1.1 %d %s\r\n" "Date: %s\r\n" "Last-Modified: %s\r\n" "Accept-Ranges: bytes\r\n" - "Content-Type: %.*s\r\n" - "Content-Length: %" INT64_FMT - "\r\n" - "%s" - "Etag: %s\r\n" - "\r\n", + "Content-Type: %.*s\r\n", status_code, status_message, current_time, last_modified, - (int) mime_type.len, mime_type.p, cl, range, etag); + (int) mime_type.len, mime_type.p); + mg_printf(nc, "Content-Length: %" INT64_FMT "\r\n", cl); + mg_printf(nc, "%sEtag: %s\r\n\r\n", range, etag); + nc->proto_data = (void *) dp; dp->cl = cl; dp->type = DATA_FILE;