Make mg send_http_file work for ESP8266 RTOS

PUBLISHED_FROM=10623cfe38e143f7e107a6494baa298c788586f0
This commit is contained in:
Marko Mikulicic 2015-09-23 11:41:15 +01:00 committed by Sergey Lyubka
parent 5351f46efb
commit 56f661e9c6

View File

@ -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(current_time, sizeof(current_time), &t);
gmt_time_string(last_modified, sizeof(last_modified), &st->st_mtime); gmt_time_string(last_modified, sizeof(last_modified), &st->st_mtime);
mime_type = get_mime_type(path, "text/plain", opts); 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, mg_printf(nc,
"HTTP/1.1 %d %s\r\n" "HTTP/1.1 %d %s\r\n"
"Date: %s\r\n" "Date: %s\r\n"
"Last-Modified: %s\r\n" "Last-Modified: %s\r\n"
"Accept-Ranges: bytes\r\n" "Accept-Ranges: bytes\r\n"
"Content-Type: %.*s\r\n" "Content-Type: %.*s\r\n",
"Content-Length: %" INT64_FMT
"\r\n"
"%s"
"Etag: %s\r\n"
"\r\n",
status_code, status_message, current_time, last_modified, 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; nc->proto_data = (void *) dp;
dp->cl = cl; dp->cl = cl;
dp->type = DATA_FILE; dp->type = DATA_FILE;