[Libreoffice-commits] online.git: loolwsd/LOOLWSD.cpp loolwsd/test
Henry Castro
hcastro at collabora.com
Thu Oct 13 20:53:02 UTC 2016
loolwsd/LOOLWSD.cpp | 29 ++++++++++++++++++++++++-----
loolwsd/test/httpwstest.cpp | 2 +-
2 files changed, 25 insertions(+), 6 deletions(-)
New commits:
commit a0a87276f99919df82cc3d32a2d3da47adacc2e6
Author: Henry Castro <hcastro at collabora.com>
Date: Thu Oct 13 16:51:14 2016 -0400
loolwsd: fix media type
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index cf22bfd..1b176eb 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -155,6 +155,7 @@ using Poco::XML::DOMWriter;
using Poco::XML::Element;
using Poco::XML::InputSource;
using Poco::XML::NodeList;
+using Poco::XML::Node;
int ClientPortNumber = DEFAULT_CLIENT_PORT_NUMBER;
int MasterPortNumber = DEFAULT_MASTER_PORT_NUMBER;
@@ -378,6 +379,28 @@ public:
class ClientRequestHandler: public HTTPRequestHandler
{
private:
+ static std::string getContentType(const std::string& fileName)
+ {
+ const std::string nodePath = Poco::format("//[@ext='%s']", Poco::Path(fileName).getExtension());
+ std::string discPath = Path(Application::instance().commandPath()).parent().toString() + "discovery.xml";
+ if (!File(discPath).exists())
+ {
+ discPath = LOOLWSD_DATADIR "/discovery.xml";
+ }
+
+ InputSource input(discPath);
+ DOMParser domParser;
+ AutoPtr<Poco::XML::Document> doc = domParser.parse(&input);
+ // TODO. discovery.xml missing application/pdf
+ Node* node = doc->getNodeByPath(nodePath);
+ if (node && (node = node->parentNode()) && node->hasAttributes())
+ {
+ return dynamic_cast<Element*>(node)->getAttribute("name");
+ }
+
+ return "application/octet-stream";
+ }
+
static void waitBridgeCompleted(const std::shared_ptr<ClientSession>& session)
{
bool isFound = false;
@@ -609,13 +632,9 @@ private:
if (filePath.isAbsolute() && File(filePath).exists())
{
response.set("Access-Control-Allow-Origin", "*");
- HTMLForm form(request);
- const std::string mimeType = form.has("mime_type")
- ? form.get("mime_type")
- : "application/octet-stream";
try
{
- response.sendFile(filePath.toString(), mimeType);
+ response.sendFile(filePath.toString(), getContentType(fileName));
responded = true;
}
catch (const Exception& exc)
diff --git a/loolwsd/test/httpwstest.cpp b/loolwsd/test/httpwstest.cpp
index 83115d2..2218a9f 100644
--- a/loolwsd/test/httpwstest.cpp
+++ b/loolwsd/test/httpwstest.cpp
@@ -879,7 +879,7 @@ void HTTPWSTest::testSlideShow()
std::string encodedDoc;
Poco::URI::encode(documentPath, ":/?", encodedDoc);
- const std::string path = "/lool/" + encodedDoc + "/" + jail + "/" + dir + "/" + name + "?mime_type=image/svg%2Bxml";
+ const std::string path = "/lool/" + encodedDoc + "/" + jail + "/" + dir + "/" + name;
std::unique_ptr<Poco::Net::HTTPClientSession> session(helpers::createSession(_uri));
Poco::Net::HTTPRequest requestSVG(Poco::Net::HTTPRequest::HTTP_GET, path);
session->sendRequest(requestSVG);
More information about the Libreoffice-commits
mailing list