summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorAngelo Mantellini <manangel@cisco.com>2019-05-17 15:49:27 +0200
committerAngelo Mantellini <manangel@cisco.com>2019-05-17 18:35:06 +0200
commit90256e9929e11ef720d9e9c6afc4342acacae654 (patch)
treeaffef7a37285207d337d592142930e99bab83b23 /apps
parentc4ead399d98d0f9084d6be1c3a44e27e8158b26a (diff)
[HICN-200] Minor issue Android
Change-Id: Iaa24bb5568bc458967b13f51b9c91c8163b2ce52 Signed-off-by: Angelo Mantellini <manangel@cisco.com>
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);