ucb/source/ucp/webdav-curl/CurlSession.cxx | 33 ++++++++++++++++------------- 1 file changed, 19 insertions(+), 14 deletions(-)
New commits: commit 8bb183f133202ebb687e0b56cc5a2938354506f7 Author: Michael Stahl <michael.st...@allotropia.de> AuthorDate: Thu Nov 25 17:16:36 2021 +0100 Commit: Michael Stahl <michael.st...@allotropia.de> CommitDate: Fri Nov 26 12:22:52 2021 +0100 ucb: webdav-curl: don't use chunked encoding for PROPFIND Sharepoint 16 responds to PROPFIND with "Transfer-Encoding: chunked" with "HTTP/1.1 200 OK" and this body: <HTML><DIV dir="ltr"><H2>Microsoft SharePoint Foundation Error.</H2>\n\n<P>\n<B>User:</B> please report details to this Web site's Webmaster.\n<P>\n\n<P>\n<B>Webmaster:</B> please see the server's application event log for more details.\n</P></DIV> Understandably, WebDAVResponseParser barfs on this: ucb/source/ucp/webdav-curl/webdavresponseparser.cxx:405: Parser destructed with existing content (!) ucb/source/ucp/webdav-curl/webdavresponseparser.cxx:942: WebDAV Parse error (!) Apparently setting Content-Length works better. Change-Id: If3eae8c2f8b9f1e1bb4ed4fc67a79a682d7d0050 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/125825 Tested-by: Jenkins Reviewed-by: Michael Stahl <michael.st...@allotropia.de> diff --git a/ucb/source/ucp/webdav-curl/CurlSession.cxx b/ucb/source/ucp/webdav-curl/CurlSession.cxx index aacc6bbed48e..ca5fedd3b280 100644 --- a/ucb/source/ucp/webdav-curl/CurlSession.cxx +++ b/ucb/source/ucp/webdav-curl/CurlSession.cxx @@ -1431,13 +1431,7 @@ auto CurlProcessor::PropFind( || (::std::get<1>(*o_pRequestedProperties) != nullptr) != (::std::get<2>(*o_pRequestedProperties) != nullptr)); - // TODO: either set CURLOPT_INFILESIZE_LARGE or chunked? - ::std::unique_ptr<curl_slist, deleter_from_fn<curl_slist, curl_slist_free_all>> pList( - curl_slist_append(nullptr, "Transfer-Encoding: chunked")); - if (!pList) - { - throw uno::RuntimeException("curl_slist_append failed"); - } + ::std::unique_ptr<curl_slist, deleter_from_fn<curl_slist, curl_slist_free_all>> pList; pList.reset(curl_slist_append(pList.release(), "Content-Type: application/xml")); if (!pList) { @@ -1464,13 +1458,11 @@ auto CurlProcessor::PropFind( throw uno::RuntimeException("curl_slist_append failed"); } - ::std::vector<CurlOption> const options{ { CURLOPT_CUSTOMREQUEST, "PROPFIND", - "CURLOPT_CUSTOMREQUEST" } }; - - uno::Reference<io::XInputStream> const xRequestInStream(io::Pipe::create(rSession.m_xContext)); - uno::Reference<io::XOutputStream> const xRequestOutStream(xRequestInStream, uno::UNO_QUERY); - assert(xRequestInStream.is()); + uno::Reference<io::XSequenceOutputStream> const xSeqOutStream( + io::SequenceOutputStream::create(rSession.m_xContext)); + uno::Reference<io::XOutputStream> const xRequestOutStream(xSeqOutStream); assert(xRequestOutStream.is()); + uno::Reference<xml::sax::XWriter> const xWriter(xml::sax::Writer::create(rSession.m_xContext)); xWriter->setOutputStream(xRequestOutStream); xWriter->startDocument(); @@ -1506,7 +1498,19 @@ auto CurlProcessor::PropFind( } xWriter->endElement("propfind"); xWriter->endDocument(); - xRequestOutStream->closeOutput(); + + uno::Reference<io::XInputStream> const xRequestInStream( + io::SequenceInputStream::createStreamFromSequence(rSession.m_xContext, + xSeqOutStream->getWrittenBytes())); + assert(xRequestInStream.is()); + + curl_off_t const len(xSeqOutStream->getWrittenBytes().getLength()); + + ::std::vector<CurlOption> const options{ + { CURLOPT_CUSTOMREQUEST, "PROPFIND", "CURLOPT_CUSTOMREQUEST" }, + // note: Sharepoint cannot handle "Transfer-Encoding: chunked" + { CURLOPT_INFILESIZE_LARGE, len, nullptr, CurlOption::Type::CurlOffT } + }; // stream for response uno::Reference<io::XInputStream> const xResponseInStream(io::Pipe::create(rSession.m_xContext)); @@ -1804,6 +1808,7 @@ auto CurlSession::PUT(OUString const& rURIReference, // lock m_Mutex after accessing global LockStore to avoid deadlock + // note: Nextcloud 20 cannot handle "Transfer-Encoding: chunked" ::std::vector<CurlOption> const options{ { CURLOPT_INFILESIZE_LARGE, len, nullptr, CurlOption::Type::CurlOffT } };