From 90256e9929e11ef720d9e9c6afc4342acacae654 Mon Sep 17 00:00:00 2001 From: Angelo Mantellini Date: Fri, 17 May 2019 15:49:27 +0200 Subject: [HICN-200] Minor issue Android Change-Id: Iaa24bb5568bc458967b13f51b9c91c8163b2ce52 Signed-off-by: Angelo Mantellini --- apps/http-server/http-server.cc | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'apps') 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(); + 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>(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 <(); ifs->open(path, ifstream::in | ios::binary); -- cgit 1.2.3-korg