aboutsummaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorMauro Sardara <msardara@cisco.com>2019-05-20 09:15:37 +0000
committerGerrit Code Review <gerrit@fd.io>2019-05-20 09:15:37 +0000
commit7d93a4e00022cc2a46b4580c8befaa629aae4bfc (patch)
tree683ce5941be6e26f455d6ab1661e07bc6e533c13 /apps
parent250e5f768a75a62b001c16932e06055fa64a1a27 (diff)
parent90256e9929e11ef720d9e9c6afc4342acacae654 (diff)
Merge "[HICN-200] Minor issue Android"
Diffstat (limited to 'apps')
-rw-r--r--apps/http-server/http-server.cc30
1 files changed, 29 insertions, 1 deletions
diff --git a/apps/http-server/http-server.cc b/apps/http-server/http-server.cc
index 9d3eac5b8..f5fabf56f 100644
--- a/apps/http-server/http-server.cc
+++ b/apps/http-server/http-server.cc
@@ -287,12 +287,40 @@ int main(int argc, char **argv) {
response->setResponseLifetime(response_lifetime);
- if (_isDirectory(path.c_str())) {
+ if (!_isDirectory(path.c_str())) {
// Check if path is within web_root_path
if (distance(web_root_path.begin(), web_root_path.end()) <=
distance(path.begin(), path.end()) &&
equal(web_root_path.begin(), web_root_path.end(), path.begin())) {
+ if (_isRegularFile(path.c_str())) {
+ auto ifs = make_shared<ifstream>();
+ ifs->open(path, ifstream::in | ios::binary);
+
+ if (*ifs) {
+ // read and send 15 MB at a time
+ streamsize buffer_size = 15 * 1024 * 1024;
+ auto buffer = make_shared<vector<char>>(buffer_size);
+
+ ifs->seekg(0, ios::end);
+ auto length = ifs->tellg();
+ ifs->seekg(0, ios::beg);
+
+ response->setResponseLength(length);
+ *response << "HTTP/1.0 200 OK\r\nContent-Length: " << length
+ << "\r\n\r\n";
+
+ default_resource_send(server, response, ifs, buffer, length);
+
+ return;
+ }
+ }
+ }
+ } else {
+ if (distance(web_root_path.begin(), web_root_path.end()) <=
+ distance(path.begin(), path.end()) &&
+ equal(web_root_path.begin(), web_root_path.end(), path.begin())) {
path += "index.html";
+ std::cout << "path: "<< path <<endl;
if (_isRegularFile(path.c_str())) {
auto ifs = make_shared<ifstream>();
ifs->open(path, ifstream::in | ios::binary);