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

Method sendFile

Sming/Components/Network/src/Network/Http/HttpResponse.cpp:65–93  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

63}
64
65bool HttpResponse::sendFile(const String& fileName, bool allowGzipFileCheck)
66{
67 auto fs = new FileStream;
68
69 if(allowGzipFileCheck) {
70 String fnCompressed = fileName + _F(".gz");
71 if(fs->open(fnCompressed)) {
72 debug_d("found %s", fnCompressed.c_str());
73 headers[HTTP_HEADER_CONTENT_ENCODING] = F("gzip");
74 return sendDataStream(fs, ContentType::fromFullFileName(fileName));
75 }
76 }
77
78 if(fs->open(fileName)) {
79 debug_d("found %s", fileName.c_str());
80 FileStat stat;
81 fs->stat(stat);
82 if(stat.compression.type == IFS::Compression::Type::GZip) {
83 headers[HTTP_HEADER_CONTENT_ENCODING] = F("gzip");
84 } else if(stat.compression.type != IFS::Compression::Type::None) {
85 debug_e("Unsupported compression type: %s", ::toString(stat.compression.type).c_str());
86 }
87 return sendDataStream(fs, ContentType::fromFullFileName(fileName));
88 }
89
90 delete fs;
91 code = HTTP_STATUS_NOT_FOUND;
92 return false;
93}
94
95bool HttpResponse::sendNamedStream(IDataSourceStream* newDataStream)
96{

Callers 3

onIndexFunction · 0.45
onFileFunction · 0.45
onFileFunction · 0.45

Calls 6

toStringFunction · 0.70
FFunction · 0.50
fromFullFileNameFunction · 0.50
openMethod · 0.45
c_strMethod · 0.45
statMethod · 0.45

Tested by

no test coverage detected