[Libreoffice-commits] online.git: 2 commits - net/Socket.cpp net/Socket.hpp test/Makefile.am test/UnitHTTP.cpp wsd/DocumentBroker.cpp
Libreoffice Gerrit user
logerrit at kemper.freedesktop.org
Wed May 22 01:56:40 UTC 2019
net/Socket.cpp | 9 ++++
net/Socket.hpp | 4 ++
test/Makefile.am | 6 ++-
test/UnitHTTP.cpp | 97 +++++++++++++++++++++++++++++++++++++++++++++++++
wsd/DocumentBroker.cpp | 13 ++++--
5 files changed, 122 insertions(+), 7 deletions(-)
New commits:
commit 83d687825dbe9212397a09547838eaf89058caad
Author: Michael Meeks <michael.meeks at collabora.com>
AuthorDate: Wed May 22 02:38:39 2019 +0100
Commit: Michael Meeks <michael.meeks at collabora.com>
CommitDate: Wed May 22 02:56:11 2019 +0100
Avoid exceptions in some shutdown corner cases.
Change-Id: I1c301dc96d925fd5d74c00bf4b9417782822a997
diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index 698f3dd98..eb8fb1eee 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -1915,11 +1915,14 @@ void ConvertToBroker::removeFile(const std::string &uriOrig)
{
if (!uriOrig.empty())
{
- // Remove source file and directory
- Poco::Path path = uriOrig;
- Poco::File(path).remove();
- Poco::File(path.makeParent()).remove();
- FileUtil::removeFile(uriOrig);
+ try {
+ // Remove source file and directory
+ Poco::Path path = uriOrig;
+ Poco::File(path).remove();
+ Poco::File(path.makeParent()).remove();
+ } catch (const std::exception &ex) {
+ LOG_ERR("Error while removing conversion temporary: '" << uriOrig << "' - " << ex.what());
+ }
}
}
commit 4f804a48fe743ac37ee45b8a4c323cad072cdb5e
Author: Michael Meeks <michael.meeks at collabora.com>
AuthorDate: Wed May 22 02:54:12 2019 +0100
Commit: Michael Meeks <michael.meeks at collabora.com>
CommitDate: Wed May 22 02:56:11 2019 +0100
Initial HTTP Expect: 100-continue implementation.
Change-Id: Ic9aa59cac5103151d91f6eb59d12313e545c7916
diff --git a/net/Socket.cpp b/net/Socket.cpp
index c1225877a..ba72e16c1 100644
--- a/net/Socket.cpp
+++ b/net/Socket.cpp
@@ -681,6 +681,15 @@ bool StreamSocket::parseHeader(const char *clientName,
LOG_DBG("Not enough content yet: ContentLength: " << contentLength << ", available: " << available);
return false;
}
+
+ if (request.getExpectContinue() && !_sentHTTPContinue)
+ {
+ LOG_TRC("#" << getFD() << " got Expect: 100-continue, sending Continue");
+ // FIXME: should validate authentication headers early too.
+ send("HTTP/1.1 100 Continue\r\n\r\n",
+ sizeof("HTTP/1.1 100 Continue\r\n\r\n") - 1);
+ _sentHTTPContinue = true;
+ }
}
catch (const Poco::Exception& exc)
{
diff --git a/net/Socket.hpp b/net/Socket.hpp
index 0764df159..5995570dc 100644
--- a/net/Socket.hpp
+++ b/net/Socket.hpp
@@ -801,6 +801,7 @@ public:
_bytesRecvd(0),
_wsState(WSState::HTTP),
_closed(false),
+ _sentHTTPContinue(false),
_shutdownSignalled(false)
{
LOG_DBG("StreamSocket ctor #" << fd);
@@ -1154,6 +1155,9 @@ protected:
/// True if we are already closed.
bool _closed;
+ /// True if we've received a Continue in response to an Expect: 100-continue
+ bool _sentHTTPContinue;
+
/// True when shutdown was requested via shutdown().
bool _shutdownSignalled;
};
diff --git a/test/Makefile.am b/test/Makefile.am
index 0432955ae..eed2abd5d 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -17,7 +17,7 @@ noinst_LTLIBRARIES = \
unit-timeout.la unit-prefork.la \
unit-storage.la unit-client.la \
unit-admin.la unit-tilecache.la \
- unit-fuzz.la unit-oob.la unit-oauth.la \
+ unit-fuzz.la unit-oob.la unit-http.la unit-oauth.la \
unit-wopi.la unit-wopi-saveas.la \
unit-wopi-ownertermination.la unit-wopi-versionrestore.la \
unit-wopi-documentconflict.la unit_wopi_renamefile.la
@@ -86,6 +86,7 @@ fakesockettest_LDADD = $(CPPUNIT_LIBS)
# unit test modules:
unit_oob_la_SOURCES = UnitOOB.cpp
+unit_http_la_SOURCES = UnitHTTP.cpp
unit_fuzz_la_SOURCES = UnitFuzz.cpp
unit_admin_la_SOURCES = UnitAdmin.cpp
unit_admin_la_LIBADD = $(CPPUNIT_LIBS)
@@ -130,7 +131,8 @@ check-local:
TESTS = unit-typing.la unit-convert.la unit-prefork.la unit-tilecache.la \
unit-timeout.la unit-oauth.la unit-wopi.la unit-wopi-saveas.la \
unit-wopi-ownertermination.la unit-wopi-versionrestore.la \
- unit-wopi-documentconflict.la unit_wopi_renamefile.la
+ unit-wopi-documentconflict.la unit_wopi_renamefile.la \
+ unit-http.la
# TESTS = unit-client.la
# TESTS += unit-admin.la
# TESTS += unit-storage.la
diff --git a/test/UnitHTTP.cpp b/test/UnitHTTP.cpp
new file mode 100644
index 000000000..d0530fe10
--- /dev/null
+++ b/test/UnitHTTP.cpp
@@ -0,0 +1,97 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <config.h>
+
+#include <cassert>
+
+#include <helpers.hpp>
+#include <Poco/Util/Application.h>
+#include <Poco/Net/StringPartSource.h>
+#include <Poco/Net/HTMLForm.h>
+#include <Poco/Net/HTTPRequest.h>
+#include <Poco/Net/HTTPResponse.h>
+#include <Poco/Net/HTTPSClientSession.h>
+
+#include <Log.hpp>
+#include <Util.hpp>
+#include <Unit.hpp>
+
+class UnitHTTP : public UnitWSD
+{
+public:
+ UnitHTTP()
+ {
+ }
+
+ void configure(Poco::Util::LayeredConfiguration& config) override
+ {
+ UnitWSD::configure(config);
+ // force HTTPS - to test harder
+ config.setBool("ssl.enable", true);
+ }
+
+ // FIXME: can hook with (UnitWSD::get().handleHttpRequest(request, message, socket)) ...
+ void invokeTest() override
+ {
+ for (int i = 0; i < 3; ++i)
+ {
+ std::unique_ptr<Poco::Net::HTTPClientSession> session(helpers::createSession(Poco::URI(helpers::getTestServerURI())));
+
+ std::string sent = "Hello world test\n";
+
+ Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_POST, "/lool/convert-to/txt");
+
+ switch(i)
+ {
+ case 0:
+ request.setExpectContinue(false);
+ break;
+ case 1:
+ request.setExpectContinue(true);
+ break;
+ default:
+ break;
+ }
+ Poco::Net::HTMLForm form;
+ form.setEncoding(Poco::Net::HTMLForm::ENCODING_MULTIPART);
+ form.set("format", "txt");
+ form.addPart("data", new Poco::Net::StringPartSource(sent, "text/plain", "foobaa.txt"));
+ form.prepareSubmit(request);
+ form.write(session->sendRequest(request));
+
+ Poco::Net::HTTPResponse response;
+ std::stringstream actualStream;
+ std::istream& responseStream = session->receiveResponse(response);
+ Poco::StreamCopier::copyStream(responseStream, actualStream);
+
+ std::string responseStr = actualStream.str();
+ responseStr.erase(0,3); // remove utf-8 bom.
+
+ if (sent != responseStr)
+ {
+ std::cerr << "Test " << i << " failed - mismatching string '" << responseStr << " vs. '" << sent << "'\n";
+ exitTest(TestResult::Failed);
+ return;
+ }
+ }
+ // Give those convertors time to save and cleanup.
+ std::this_thread::sleep_for(std::chrono::milliseconds(1000));
+
+ std::cerr << "All tests passed.\n";
+ exitTest(TestResult::Ok);
+ }
+};
+
+UnitBase *unit_create_wsd(void)
+{
+ return new UnitHTTP();
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
More information about the Libreoffice-commits
mailing list