MCPcopy Create free account
hub / github.com/SmingHub/Sming / sendFile

Function sendFile

samples/Basic_WebSkeletonApp/app/webserver.cpp:40–63  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

38#undef XX
39
40void sendFile(const String& fileName, HttpServerConnection& connection)
41{
42 auto response = connection.getResponse();
43
44 String compressed = fileName + ".gz";
45 auto content = fileMap[compressed];
46 if(content) {
47 response->headers[HTTP_HEADER_CONTENT_ENCODING] = _F("gzip");
48 } else {
49 content = fileMap[fileName];
50 if(!content) {
51 debug_w("File '%s' not found", fileName.c_str());
52 response->code = HTTP_STATUS_NOT_FOUND;
53 return;
54 }
55 }
56
57 debug_i("found %s in fileMap", String(content.key()).c_str());
58 auto stream = new FSTR::Stream(content.content());
59 response->sendDataStream(stream, ContentType::fromFullFileName(fileName));
60
61 // Use client caching for better performance.
62 // response->setCache(86400, true);
63}
64
65#else
66

Callers 4

onIndexFunction · 0.85
onConfigurationFunction · 0.85
onFileFunction · 0.85
DelayStreamMethod · 0.85

Calls 5

getResponseMethod · 0.80
StringClass · 0.50
fromFullFileNameFunction · 0.50
c_strMethod · 0.45
sendDataStreamMethod · 0.45

Tested by

no test coverage detected