net/Socket.cpp | 9 +++++ net/Socket.hpp | 4 ++ test/Makefile.am | 4 +- test/UnitHTTP.cpp | 97 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 112 insertions(+), 2 deletions(-)
New commits: commit 1b67625a676c65e9c55bfce909492eaa77334ed5 Author: Michael Meeks <michael.me...@collabora.com> AuthorDate: Wed May 22 02:54:12 2019 +0100 Commit: Andras Timar <andras.ti...@collabora.com> CommitDate: Thu Jun 13 10:14:58 2019 +0200 Initial HTTP Expect: 100-continue implementation. Change-Id: Ic9aa59cac5103151d91f6eb59d12313e545c7916 Reviewed-on: https://gerrit.libreoffice.org/72746 Reviewed-by: Andras Timar <andras.ti...@collabora.com> Tested-by: Andras Timar <andras.ti...@collabora.com> diff --git a/net/Socket.cpp b/net/Socket.cpp index 2d35f6b02..2737c6f1c 100644 --- a/net/Socket.cpp +++ b/net/Socket.cpp @@ -485,6 +485,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 2f0217d76..de20991e1 100644 --- a/net/Socket.hpp +++ b/net/Socket.hpp @@ -782,6 +782,7 @@ public: _bytesRecvd(0), _wsState(WSState::HTTP), _closed(false), + _sentHTTPContinue(false), _shutdownSignalled(false) { LOG_DBG("StreamSocket ctor #" << fd); @@ -1139,6 +1140,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 eacb3355a..eab241a95 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 \ @@ -85,6 +85,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) @@ -129,7 +130,6 @@ TESTS = 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-loadencoded.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: */ _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits