1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "SerfRequestProcessorImpl.hxx"
24 // Define a magic value that is used by serf to reset chunked
25 // encoding. The value definition is not supported by serf, hence the
27 static const apr_int64_t
SERF_UNKNOWN_LENGTH (-1);
30 namespace http_dav_ucp
33 SerfRequestProcessorImpl::SerfRequestProcessorImpl( const char* inPath
,
34 const DAVRequestHeaders
& inRequestHeaders
)
36 , mrRequestHeaders( inRequestHeaders
)
37 , mbUseChunkedEncoding( false )
41 SerfRequestProcessorImpl::~SerfRequestProcessorImpl()
45 const char* SerfRequestProcessorImpl::getPathStr() const
50 void SerfRequestProcessorImpl::activateChunkedEncoding()
52 mbUseChunkedEncoding
= true;
55 bool SerfRequestProcessorImpl::useChunkedEncoding() const
57 return mbUseChunkedEncoding
;
61 void SerfRequestProcessorImpl::handleChunkedEncoding (
62 serf_bucket_t
* pRequestBucket
,
63 apr_int64_t nLength
) const
65 if (pRequestBucket
!= NULL
)
67 if (useChunkedEncoding())
69 // Activate chunked encoding.
70 serf_bucket_request_set_CL(pRequestBucket
, SERF_UNKNOWN_LENGTH
);
74 // Deactivate chunked encoding by setting the length.
75 serf_bucket_request_set_CL(pRequestBucket
, nLength
);
81 void SerfRequestProcessorImpl::setRequestHeaders( serf_bucket_t
* inoutSerfHeaderBucket
)
83 bool bHasUserAgent( false );
84 DAVRequestHeaders::const_iterator
aHeaderIter( mrRequestHeaders
.begin() );
85 const DAVRequestHeaders::const_iterator
aEnd( mrRequestHeaders
.end() );
87 while ( aHeaderIter
!= aEnd
)
89 const OString aHeader
= OUStringToOString( (*aHeaderIter
).first
,
90 RTL_TEXTENCODING_UTF8
);
91 const OString aValue
= OUStringToOString( (*aHeaderIter
).second
,
92 RTL_TEXTENCODING_UTF8
);
94 SAL_INFO("ucb.ucp.webdav", "Request Header - \"" << aHeader
<< ": " << aValue
<< "\"");
96 bHasUserAgent
= aHeaderIter
->first
== "User-Agent";
98 serf_bucket_headers_setc( inoutSerfHeaderBucket
,
105 if ( !bHasUserAgent
)
107 serf_bucket_headers_set( inoutSerfHeaderBucket
,
108 "User-Agent", "LibreOffice" );
111 serf_bucket_headers_set( inoutSerfHeaderBucket
, "Accept-Encoding", "gzip");
114 bool SerfRequestProcessorImpl::processSerfResponseBucket( serf_request_t
* /*inSerfRequest*/,
115 serf_bucket_t
* inSerfResponseBucket
,
116 apr_pool_t
* /*inAprPool*/,
117 apr_status_t
& outStatus
)
123 outStatus
= serf_bucket_read(inSerfResponseBucket
, 8096, &data
, &len
);
124 if (SERF_BUCKET_READ_ERROR(outStatus
))
131 processChunkOfResponseData( data
, len
);
134 /* are we done yet? */
135 if (APR_STATUS_IS_EOF(outStatus
))
137 handleEndOfResponseData( inSerfResponseBucket
);
143 /* have we drained the response so far? */
144 if ( APR_STATUS_IS_EAGAIN( outStatus
) )
154 } // namespace http_dav_ucp
156 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */