HttpConfigurationHandler.h
Go to the documentation of this file.
1 /*--------------------------------------------------------------------------------------+
2 |
3 | Supplied under applicable software license agreement.
4 |
5 | Copyright (c) 2018 Bentley Systems, Incorporated. All rights reserved.
6 |
7 +---------------------------------------------------------------------------------------*/
8 #pragma once
9 
11 #include <BeHttp/HttpRequest.h>
12 #include <BeHttp/IHttpHandler.h>
13 
15 
16 /*--------------------------------------------------------------------------------------+
17 * @bsiclass Bentley Systems
18 +---------------+---------------+---------------+---------------+---------------+------*/
20 {
21 private:
22  IHttpHandlerPtr m_handler;
23  std::function<void(RequestR request)> m_configuration;
24 
25 public:
29  std::function<void(Request& request)> configuration,
30  IHttpHandlerPtr customHandler = nullptr
31  ) : m_handler(customHandler ? customHandler : DefaultHttpHandler::GetInstance()), m_configuration(configuration) {}
33 
35  virtual Tasks::AsyncTaskPtr<Response> _PerformRequest(RequestCR request) override
36  {
37  if (!m_configuration)
38  return m_handler->_PerformRequest(request);
39 
40  Request configuredRequest = request;
41  m_configuration(configuredRequest);
42  return m_handler->_PerformRequest(configuredRequest);
43  }
44 };
45 
Definition: IHttpHandler.h:20
Request const & RequestCR
Definition: Http.h:24
#define BEGIN_BENTLEY_HTTP_NAMESPACE
Definition: Http.h:17
virtual ~HttpConfigurationHandler()
Definition: HttpConfigurationHandler.h:32
Definition: DefaultHttpHandler.h:18
HttpConfigurationHandler(std::function< void(Request &request)> configuration, IHttpHandlerPtr customHandler=nullptr)
Definition: HttpConfigurationHandler.h:28
BEGIN_BENTLEY_HTTP_NAMESPACE typedef std::shared_ptr< struct IHttpHandler > IHttpHandlerPtr
Definition: IHttpHandler.h:15
Definition: HttpRequest.h:26
Definition: HttpConfigurationHandler.h:19
#define END_BENTLEY_HTTP_NAMESPACE
Definition: Http.h:18
virtual Tasks::AsyncTaskPtr< Response > _PerformRequest(RequestCR request) override
Configure and Perform HttpRequest.
Definition: HttpConfigurationHandler.h:35

Copyright © 2017 Bentley Systems, Incorporated. All rights reserved.