[Libreoffice-commits] online.git: net/Socket.cpp net/Socket.hpp wsd/Admin.cpp wsd/ClientSession.cpp wsd/FileServer.cpp wsd/LOOLWSD.cpp
Ashod Nakashian
ashod.nakashian at collabora.co.uk
Mon Apr 24 04:52:21 UTC 2017
net/Socket.cpp | 12 ++++++++++++
net/Socket.hpp | 29 +++++++++++------------------
wsd/Admin.cpp | 1 +
wsd/ClientSession.cpp | 4 +++-
wsd/FileServer.cpp | 1 +
wsd/LOOLWSD.cpp | 3 ++-
6 files changed, 30 insertions(+), 20 deletions(-)
New commits:
commit 8b3a2ed9d7fd3df4b6830a011222f0c387bb2364
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date: Sun Apr 23 21:25:09 2017 -0400
wsd: reduce included headers
Change-Id: I3107b18b2edae34a76e9f56a5cbd24836b1b57c0
Reviewed-on: https://gerrit.libreoffice.org/36872
Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
Tested-by: Ashod Nakashian <ashnakash at gmail.com>
diff --git a/net/Socket.cpp b/net/Socket.cpp
index c8780327..ad912880 100644
--- a/net/Socket.cpp
+++ b/net/Socket.cpp
@@ -17,6 +17,7 @@
#include <Poco/DateTime.h>
#include <Poco/DateTimeFormat.h>
#include <Poco/DateTimeFormatter.h>
+#include <Poco/Net/HTTPResponse.h>
#include "SigUtil.hpp"
#include "Socket.hpp"
@@ -173,6 +174,17 @@ void StreamSocket::dumpState(std::ostream& os)
dump_hex("\t\toutBuffer:\n", "\t\t", _inBuffer);
}
+void StreamSocket::send(Poco::Net::HTTPResponse& response)
+{
+ response.set("User-Agent", HTTP_AGENT_STRING);
+ response.set("Date", Poco::DateTimeFormatter::format(Poco::Timestamp(), Poco::DateTimeFormat::HTTP_FORMAT));
+
+ std::ostringstream oss;
+ response.write(oss);
+
+ send(oss.str());
+}
+
void SocketPoll::dumpState(std::ostream& os)
{
// FIXME: NOT thread-safe! _pollSockets is modified from the polling thread!
diff --git a/net/Socket.hpp b/net/Socket.hpp
index 6f1397f0..014f023d 100644
--- a/net/Socket.hpp
+++ b/net/Socket.hpp
@@ -31,13 +31,19 @@
#include <thread>
#include <chrono>
-#include <Poco/Net/HTTPResponse.h>
-
#include "Common.hpp"
#include "Log.hpp"
#include "Util.hpp"
#include "SigUtil.hpp"
+namespace Poco
+{
+ namespace Net
+ {
+ class HTTPResponse;
+ }
+}
+
/// A non-blocking, streaming socket.
class Socket
{
@@ -705,13 +711,8 @@ public:
}
/// Sends HTTP response.
- void send(Poco::Net::HTTPResponse& response)
- {
- response.set("User-Agent", HTTP_AGENT_STRING);
- std::ostringstream oss;
- response.write(oss);
- send(oss.str());
- }
+ /// Adds Date and User-Agent.
+ void send(Poco::Net::HTTPResponse& response);
/// Reads data by invoking readData() and buffering.
/// Return false iff the socket is closed.
@@ -914,18 +915,10 @@ protected:
namespace HttpHelper
{
+ /// Sends file as HTTP response.
void sendFile(const std::shared_ptr<StreamSocket>& socket, const std::string& path, const std::string& mediaType,
Poco::Net::HTTPResponse& response, bool noCache = false, bool deflate = false,
const bool headerOnly = false);
-
- inline void sendFile(const std::shared_ptr<StreamSocket>& socket, const std::string& path,
- const std::string& mediaType, bool noCache = false, bool deflate = false,
- const bool headerOnly = false)
-
- {
- Poco::Net::HTTPResponse response;
- sendFile(socket, path, mediaType, response, noCache, deflate, headerOnly);
- }
};
#endif
diff --git a/wsd/Admin.cpp b/wsd/Admin.cpp
index f4bbe1de..700b860b 100644
--- a/wsd/Admin.cpp
+++ b/wsd/Admin.cpp
@@ -15,6 +15,7 @@
#include <Poco/Net/HTTPCookie.h>
#include <Poco/Net/HTTPRequest.h>
+#include <Poco/Net/HTTPResponse.h>
#include <Poco/StringTokenizer.h>
#include "Admin.hpp"
diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp
index 11db33af..0bec1538 100644
--- a/wsd/ClientSession.cpp
+++ b/wsd/ClientSession.cpp
@@ -13,6 +13,7 @@
#include <fstream>
+#include <Poco/Net/HTTPResponse.h>
#include <Poco/URI.h>
#include "Common.hpp"
@@ -599,7 +600,8 @@ bool ClientSession::handleKitToClientMessage(const char* buffer, const int lengt
std::string encodedFilePath;
Poco::URI::encode(resultURL.getPath(), "", encodedFilePath);
LOG_TRC("Sending file: " << encodedFilePath);
- HttpHelper::sendFile(_saveAsSocket, encodedFilePath, mimeType);
+ Poco::Net::HTTPResponse response;
+ HttpHelper::sendFile(_saveAsSocket, encodedFilePath, mimeType, response);
}
// Conversion is done, cleanup this fake session.
diff --git a/wsd/FileServer.cpp b/wsd/FileServer.cpp
index 43216996..b49d2c34 100644
--- a/wsd/FileServer.cpp
+++ b/wsd/FileServer.cpp
@@ -19,6 +19,7 @@
#include <Poco/FileStream.h>
#include <Poco/Net/HTTPCookie.h>
#include <Poco/Net/HTTPBasicCredentials.h>
+#include <Poco/Net/HTTPResponse.h>
#include <Poco/Net/HTMLForm.h>
#include <Poco/Net/HTTPRequest.h>
#include <Poco/Net/NameValueCollection.h>
diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index c604206e..4e136d4e 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -1747,7 +1747,8 @@ private:
}
auto socket = _socket.lock();
- HttpHelper::sendFile(socket, faviconPath, mimeType);
+ Poco::Net::HTTPResponse response;
+ HttpHelper::sendFile(socket, faviconPath, mimeType, response);
socket->shutdown();
}
More information about the Libreoffice-commits
mailing list