summaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorRamesh Iyyar <rameshi1@in.ibm.com>2019-07-05 08:04:42 -0500
committerEd Tanous <ed.tanous@intel.com>2019-08-02 16:31:16 +0000
commitd9207047c5883b610b462d9b661f45f99104498d (patch)
tree1088e30eb9bdb91dd6d850cda53735c0459056b7 /include
parentfdf43a3fc87728ca0455c1ee2931be821f83b51d (diff)
downloadbmcweb-d9207047c5883b610b462d9b661f45f99104498d.tar.gz
bmcweb-d9207047c5883b610b462d9b661f45f99104498d.zip
Fix for Download dump file with original file name
Issue: The downloaded dump file name is having dump id instead of actual dump file name. Solution: Added "Content-Disposition" header into http response packet with filename as actual dump file name. So, The downloaded dump file will be saved in actual dump file name when downloading the dump file by using dump id. Tested By: - curl -O -J -c cjar -b cjar -k -H "X-Auth-Token: $bmc_token" https: //$bmc_ip/download/dump/DUMP_ID Change-Id: Id4726da20081e7d57d62038f672169f440edecfd Signed-off-by: Ramesh Iyyar <rameshi1@in.ibm.com>
Diffstat (limited to 'include')
-rw-r--r--include/openbmc_dbus_rest.hpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/include/openbmc_dbus_rest.hpp b/include/openbmc_dbus_rest.hpp
index 0aa23e2..5b9b738 100644
--- a/include/openbmc_dbus_rest.hpp
+++ b/include/openbmc_dbus_rest.hpp
@@ -23,6 +23,7 @@
#include <dbus_utility.hpp>
#include <filesystem>
#include <fstream>
+#include <regex>
#include <sdbusplus/message/types.hpp>
namespace crow
@@ -2110,7 +2111,30 @@ template <typename... Middlewares> void requestRoutes(Crow<Middlewares...> &app)
{
continue;
}
+
res.addHeader("Content-Type", "application/octet-stream");
+
+ // Assuming only one dump file will be present in the dump id
+ // directory
+ std::string dumpFileName = file.path().filename().string();
+
+ // Filename should be in alphanumeric, dot and underscore
+ // Its based on phosphor-debug-collector application dumpfile
+ // format
+ std::regex dumpFileRegex("[a-zA-Z0-9\\._]+");
+ if (!std::regex_match(dumpFileName, dumpFileRegex))
+ {
+ BMCWEB_LOG_ERROR << "Invalid dump filename "
+ << dumpFileName;
+ res.result(boost::beast::http::status::not_found);
+ res.end();
+ return;
+ }
+ std::string contentDispositionParam =
+ "attachment; filename=\"" + dumpFileName + "\"";
+
+ res.addHeader("Content-Disposition", contentDispositionParam);
+
res.body() = {std::istreambuf_iterator<char>(readFile),
std::istreambuf_iterator<char>()};
res.end();
OpenPOWER on IntegriCloud