[Libreoffice-commits] online.git: 2 commits - configure.ac Makefile.am net/Socket.cpp net/Socket.hpp wsd/FileServer.cpp
Michael Meeks
michael.meeks at collabora.com
Thu Mar 30 11:09:33 UTC 2017
Makefile.am | 4 +-
configure.ac | 2 +
net/Socket.cpp | 84 +++++++++++++++++++++++++++++++++++++----------------
net/Socket.hpp | 6 +--
wsd/FileServer.cpp | 3 +
5 files changed, 68 insertions(+), 31 deletions(-)
New commits:
commit a4ac00d8546e059a76285d05ca040e9cb92a8fa9
Author: Michael Meeks <michael.meeks at collabora.com>
Date: Thu Mar 30 12:08:47 2017 +0100
Add zlib cflags and libs to configuration.
diff --git a/Makefile.am b/Makefile.am
index 80aed7c6..a5536b3b 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -20,13 +20,13 @@ loolwsdconfig_DATA = loolwsd.xml \
ACLOCAL_AMFLAGS = -I m4
# quick and easy for now.
-include_paths = -I${top_srcdir}/common -I${top_srcdir}/net -I${top_srcdir}/wsd -I${top_srcdir}/kit
+include_paths = -I${top_srcdir}/common -I${top_srcdir}/net -I${top_srcdir}/wsd -I${top_srcdir}/kit ${ZLIB_CFLAGS}
AM_CPPFLAGS = -pthread -DLOOLWSD_DATADIR='"@LOOLWSD_DATADIR@"' \
-DLOOLWSD_CONFIGDIR='"@LOOLWSD_CONFIGDIR@"' \
-DDEBUG_ABSSRCDIR='"@abs_srcdir@"' \
${include_paths}
-AM_LDFLAGS = -pthread -Wl,-E
+AM_LDFLAGS = -pthread -Wl,-E $(ZLIB_LIBS)
loolforkit_LDFLAGS = -pthread -Wl,-E,-rpath,/snap/loolwsd/current/usr/lib
loolforkit_nocaps_LDFLAGS = -pthread -Wl,-E,-rpath,/snap/loolwsd/current/usr/lib
loolmount_LDFLAGS = -pthread -Wl,-E,-rpath,/snap/loolwsd/current/usr/lib
diff --git a/configure.ac b/configure.ac
index d89845da..f5290674 100644
--- a/configure.ac
+++ b/configure.ac
@@ -237,6 +237,8 @@ AS_IF([test `uname -s` = Linux],
[],
[AC_MSG_ERROR([libcap not available?])])])
+PKG_CHECK_MODULES([ZLIB], [zlib])
+
PKG_CHECK_MODULES([CPPUNIT], [cppunit])
AS_IF([test "$enable_ssl" != "no"],
diff --git a/net/Socket.cpp b/net/Socket.cpp
index 62896921..fdeb8677 100644
--- a/net/Socket.cpp
+++ b/net/Socket.cpp
@@ -13,7 +13,7 @@
#include <ctype.h>
#include <iomanip>
#include <zlib.h>
-
+
#include <Poco/DateTime.h>
#include <Poco/DateTimeFormat.h>
#include <Poco/DateTimeFormatter.h>
commit 432204566764e88266370738686ed6a8d1dd31c4
Author: dewana-dewan <iit2015097 at iiita.ac.in>
Date: Sun Mar 19 21:15:29 2017 +0530
tdf#106579 - serving gzipped file content
Change-Id: I320b22babf1bf65a0f1d4b1809a6ffb1f5ec8344
diff --git a/net/Socket.cpp b/net/Socket.cpp
index cb863b1f..62896921 100644
--- a/net/Socket.cpp
+++ b/net/Socket.cpp
@@ -12,7 +12,8 @@
#include <stdio.h>
#include <ctype.h>
#include <iomanip>
-
+#include <zlib.h>
+
#include <Poco/DateTime.h>
#include <Poco/DateTimeFormat.h>
#include <Poco/DateTimeFormatter.h>
@@ -181,7 +182,7 @@ void SocketPoll::dumpState(std::ostream& os)
namespace HttpHelper
{
void sendFile(const std::shared_ptr<StreamSocket>& socket, const std::string& path,
- Poco::Net::HTTPResponse& response, bool noCache)
+ Poco::Net::HTTPResponse& response, bool noCache, bool deflate)
{
struct stat st;
if (stat(path.c_str(), &st) != 0)
@@ -191,14 +192,6 @@ namespace HttpHelper
return;
}
- int bufferSize = std::min(st.st_size, (off_t)Socket::MaximumSendBufferSize);
- if (st.st_size >= socket->getSendBufferSize())
- {
- socket->setSocketBufferSize(bufferSize);
- bufferSize = socket->getSendBufferSize();
- }
-
- response.setContentLength(st.st_size);
response.set("User-Agent", HTTP_AGENT_STRING);
response.set("Date", Poco::DateTimeFormatter::format(Poco::Timestamp(), Poco::DateTimeFormat::HTTP_FORMAT));
if (!noCache)
@@ -208,26 +201,67 @@ namespace HttpHelper
response.set("ETag", "\"" LOOLWSD_VERSION_HASH "\"");
}
- std::ostringstream oss;
- response.write(oss);
- const std::string header = oss.str();
- LOG_TRC("#" << socket->getFD() << ": Sending file [" << path << "]: " << header);
- socket->send(header);
+ if(!deflate)
+ {
+ int bufferSize = std::min(st.st_size, (off_t)Socket::MaximumSendBufferSize);
+ if (st.st_size >= socket->getSendBufferSize())
+ {
+ socket->setSocketBufferSize(bufferSize);
+ bufferSize = socket->getSendBufferSize();
+ }
+
+ response.setContentLength(st.st_size);
+ std::ostringstream oss;
+ response.write(oss);
+ const std::string header = oss.str();
+ LOG_TRC("#" << socket->getFD() << ": Sending file [" << path << "]: " << header);
+ socket->send(header);
- std::ifstream file(path, std::ios::binary);
- bool flush = true;
- do
+ std::ifstream file(path, std::ios::binary);
+ bool flush = true;
+ do
+ {
+ char buf[bufferSize];
+ file.read(buf, sizeof(buf));
+ const int size = file.gcount();
+ if (size > 0)
+ socket->send(buf, size, flush);
+ else
+ break;
+ flush = false;
+ }
+ while (file);
+ }
+ else
{
+ response.set("Content-Encoding", "deflate");
+ std::ostringstream oss;
+ response.write(oss);
+ const std::string header = oss.str();
+ LOG_TRC("#" << socket->getFD() << ": Sending file [" << path << "]: " << header);
+ socket->send(header);
+
+ std::ifstream file(path, std::ios::binary);
+ uLong bufferSize;
+ bufferSize = st.st_size;
char buf[bufferSize];
- file.read(buf, sizeof(buf));
- const int size = file.gcount();
- if (size > 0)
- socket->send(buf, size, flush);
- else
- break;
- flush = false;
+ bool flush = true;
+ do
+ {
+ unsigned int a = 9;
+ file.read(buf, sizeof(buf));
+ long unsigned int size = file.gcount();
+ long unsigned int compSize = compressBound(size);
+ char cbuf[compSize];
+ compress2((Bytef *)&cbuf, &compSize, (Bytef *)&buf, size, a) ;
+ if (size > 0)
+ socket->send(cbuf, compSize, flush);
+ else
+ break;
+ flush = false;
+ }
+ while(file);
}
- while (file);
}
}
diff --git a/net/Socket.hpp b/net/Socket.hpp
index 111b32df..4767d26d 100644
--- a/net/Socket.hpp
+++ b/net/Socket.hpp
@@ -856,14 +856,14 @@ protected:
namespace HttpHelper
{
void sendFile(const std::shared_ptr<StreamSocket>& socket, const std::string& path,
- Poco::Net::HTTPResponse& response, bool noCache = false);
+ Poco::Net::HTTPResponse& response, bool noCache = false, bool deflate = false);
inline void sendFile(const std::shared_ptr<StreamSocket>& socket, const std::string& path,
- const std::string& mediaType, bool noCache = false)
+ const std::string& mediaType, bool noCache = false, bool deflate = false)
{
Poco::Net::HTTPResponse response;
response.setContentType(mediaType);
- sendFile(socket, path, response, noCache);
+ sendFile(socket, path, response, noCache, deflate);
}
};
diff --git a/wsd/FileServer.cpp b/wsd/FileServer.cpp
index 58fe90c2..0f987579 100644
--- a/wsd/FileServer.cpp
+++ b/wsd/FileServer.cpp
@@ -194,7 +194,8 @@ void FileServerRequestHandler::handleRequest(const HTTPRequest& request, Poco::M
}
response.setContentType(mimeType);
- HttpHelper::sendFile(socket, filepath, response, noCache);
+ bool deflate = request.hasToken("Accept-Encoding", "deflate");
+ HttpHelper::sendFile(socket, filepath, response, noCache, deflate);
}
}
catch (const Poco::Net::NotAuthenticatedException& exc)
More information about the Libreoffice-commits
mailing list