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

Function onFile

samples/HttpServer_ConfigNetwork/app/application.cpp:79–98  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

77}
78
79void onFile(HttpRequest& request, HttpResponse& response)
80{
81 if(lastModified.length() > 0 && request.headers[HTTP_HEADER_IF_MODIFIED_SINCE] == lastModified) {
82 response.code = HTTP_STATUS_NOT_MODIFIED;
83 return;
84 }
85
86 String file = request.uri.getRelativePath();
87
88 if(file[0] == '.') {
89 response.code = HTTP_STATUS_FORBIDDEN;
90 } else {
91 if(lastModified.length() > 0) {
92 response.headers[HTTP_HEADER_LAST_MODIFIED] = lastModified;
93 }
94
95 response.setCache(86400, true); // It's important to use cache for better performance.
96 response.sendFile(file);
97 }
98}
99
100void onAjaxNetworkList(HttpRequest& request, HttpResponse& response)
101{

Callers

nothing calls this directly

Calls 4

getRelativePathMethod · 0.80
setCacheMethod · 0.80
lengthMethod · 0.45
sendFileMethod · 0.45

Tested by

no test coverage detected