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 "SerfHeadReqProcImpl.hxx"
22 using namespace com::sun::star
;
24 namespace http_dav_ucp
27 SerfHeadReqProcImpl::SerfHeadReqProcImpl( const char* inPath
,
28 const DAVRequestHeaders
& inRequestHeaders
,
29 const std::vector
< OUString
> & inHeaderNames
,
30 DAVResource
& ioResource
)
31 : SerfRequestProcessorImpl( inPath
, inRequestHeaders
)
32 , mpHeaderNames( &inHeaderNames
)
33 , mpResource( &ioResource
)
37 SerfHeadReqProcImpl::~SerfHeadReqProcImpl()
41 serf_bucket_t
* SerfHeadReqProcImpl::createSerfRequestBucket( serf_request_t
* inSerfRequest
)
43 // create serf request
44 serf_bucket_t
*req_bkt
= serf_request_bucket_request_create( inSerfRequest
,
49 serf_request_get_alloc( inSerfRequest
) );
51 // set request header fields
52 serf_bucket_t
* hdrs_bkt
= serf_bucket_request_get_headers( req_bkt
);
53 // general header fields provided by caller
54 setRequestHeaders( hdrs_bkt
);
59 void SerfHeadReqProcImpl::processChunkOfResponseData( const char* /*data*/,
67 apr_status_t
Serf_ProcessResponseHeader( void* inUserData
,
68 const char* inHeaderName
,
69 const char* inHeaderValue
)
71 SerfHeadReqProcImpl
* pReqProcImpl
= static_cast< SerfHeadReqProcImpl
* >( inUserData
);
72 pReqProcImpl
->processSingleResponseHeader( inHeaderName
,
77 } // end of anonymous namespace
79 void SerfHeadReqProcImpl::handleEndOfResponseData( serf_bucket_t
* inSerfResponseBucket
)
81 // read response header, if requested
82 if ( mpHeaderNames
!= nullptr && mpResource
!= nullptr )
84 serf_bucket_t
* SerfHeaderBucket
= serf_bucket_response_get_headers( inSerfResponseBucket
);
85 if ( SerfHeaderBucket
!= nullptr )
87 serf_bucket_headers_do( SerfHeaderBucket
,
88 Serf_ProcessResponseHeader
,
94 void SerfHeadReqProcImpl::processSingleResponseHeader( const char* inHeaderName
,
95 const char* inHeaderValue
)
97 OUString
aHeaderName( OUString::createFromAscii( inHeaderName
) );
99 bool bStoreHeaderField
= false;
101 if ( mpHeaderNames
->empty() )
103 // store all header fields
104 bStoreHeaderField
= true;
108 // store only header fields which are requested
109 bStoreHeaderField
= std::any_of(mpHeaderNames
->begin(), mpHeaderNames
->end(),
110 [&aHeaderName
](const OUString
& rHeaderName
) {
111 // header names are case insensitive
112 return rHeaderName
.equalsIgnoreAsciiCase( aHeaderName
);
116 if ( bStoreHeaderField
)
118 DAVPropertyValue thePropertyValue
;
119 thePropertyValue
.IsCaseSensitive
= false;
120 thePropertyValue
.Name
= aHeaderName
;
121 thePropertyValue
.Value
<<= OUString::createFromAscii( inHeaderValue
);
122 mpResource
->properties
.push_back( thePropertyValue
);
126 } // namespace http_dav_ucp
128 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */