HttpClient.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 
10 #include <Bentley/RefCounted.h>
11 #include <Bentley/WString.h>
12 #include <Bentley/bmap.h>
13 #include <functional>
14 #include <atomic>
15 
16 #include <BeHttp/Http.h>
18 #include <BeHttp/HttpRequest.h>
19 #include <BeHttp/HttpResponse.h>
20 #include <BeHttp/IHttpHandler.h>
21 
23 
24 /*--------------------------------------------------------------------------------------+
25 * @bsiclass Bentley Systems
26 +---------------+---------------+---------------+---------------+---------------+------*/
27 struct HttpClient
28 {
29 private:
30  IHttpHeaderProviderPtr m_defaultHeadersProvider;
31  IHttpHandlerPtr m_handler;
32 
33 public:
37  BEHTTP_EXPORT HttpClient(IHttpHeaderProviderPtr defaultHeadersProvider = nullptr, IHttpHandlerPtr customHandler = nullptr);
38 
39  // Initialize HttpClient before using any function related to http requests
40  BEHTTP_EXPORT static void Initialize(BeFileNameCR assetsDirectoryPath);
42 
43  // Methods for grouping multiple network requests to one activity
44  BEHTTP_EXPORT static void BeginNetworkActivity();
45  BEHTTP_EXPORT static void EndNetworkActivity();
46 
47  BEHTTP_EXPORT static bool IsNetworkActive();
48 
49  // Use percent escape for URLs
50  BEHTTP_EXPORT static Utf8String EscapeString(Utf8StringCR inStr);
51  // Unsecape percent encoding
52  BEHTTP_EXPORT static Utf8String UnescapeString (Utf8StringCR inStr);
53 
55  BEHTTP_EXPORT static BentleyStatus HttpDateToUnixMillis(uint64_t& unixMilliseconds, Utf8CP dateStr);
56 
57  // Create requests with client info
63 };
64 
66 typedef const HttpClient& HttpClientCR;
67 
struct Bentley::BeFileName const & BeFileNameCR
Definition: Bentley.h:242
#define BEGIN_BENTLEY_HTTP_NAMESPACE
Definition: Http.h:17
static BEHTTP_EXPORT void EndNetworkActivity()
BEHTTP_EXPORT Request CreatePostRequest(Utf8StringCR url) const
static BEHTTP_EXPORT void BeginNetworkActivity()
BEHTTP_EXPORT Request CreateRequest(Utf8StringCR url, Utf8StringCR method) const
struct Bentley::Utf8String const & Utf8StringCR
Definition: Bentley.h:241
#define BEHTTP_EXPORT
Definition: Http.h:14
unsigned long long uint64_t
Definition: Bentley.r.h:95
BentleyStatus
Definition: Bentley.h:208
BEHTTP_EXPORT Request CreateGetRequest(Utf8StringCR url) const
static BEHTTP_EXPORT Utf8String UnescapeString(Utf8StringCR inStr)
BEGIN_BENTLEY_HTTP_NAMESPACE typedef std::shared_ptr< struct IHttpHandler > IHttpHandlerPtr
Definition: IHttpHandler.h:15
Definition: HttpRequest.h:26
const HttpClient & HttpClientCR
Definition: HttpClient.h:66
BEGIN_BENTLEY_HTTP_NAMESPACE typedef std::shared_ptr< struct IHttpHeaderProvider > IHttpHeaderProviderPtr
Definition: IHttpHeaderProvider.h:17
HttpClient & HttpClientR
Definition: HttpClient.h:65
Definition: HttpClient.h:27
Utf8Char const * Utf8CP
Definition: Bentley.h:229
#define END_BENTLEY_HTTP_NAMESPACE
Definition: Http.h:18
static BEHTTP_EXPORT BentleyStatus HttpDateToUnixMillis(uint64_t &unixMilliseconds, Utf8CP dateStr)
Handle date formats specified in RFC 822 (updated by RFC 1123), RFC 850 (obsoleted by RFC 1036) and A...
static BEHTTP_EXPORT BeFileNameCR GetAssetsDirectoryPath()
static BEHTTP_EXPORT bool IsNetworkActive()
static BEHTTP_EXPORT void Initialize(BeFileNameCR assetsDirectoryPath)
static BEHTTP_EXPORT Utf8String EscapeString(Utf8StringCR inStr)
BEHTTP_EXPORT Request CreateGetJsonRequest(Utf8StringCR url, Utf8StringCR etag=nullptr) const
BEHTTP_EXPORT HttpClient(IHttpHeaderProviderPtr defaultHeadersProvider=nullptr, IHttpHandlerPtr customHandler=nullptr)
Construct new client with predefined configuration.

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