HttpHandler.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 <DgnPlatform/DgnCore.h>
11 
13 
14 struct HttpHandler;
15 
16 //=======================================================================================
17 // @bsiclass Bentley Systems
18 //=======================================================================================
20  {
25  Aborted,
26  Success,
27  };
28 
29 //=======================================================================================
30 // @bsiclass Bentley Systems
31 //=======================================================================================
32 enum class HttpResponseStatus : long
33  {
34  Unknown = -1,
35 
36  // Successful
37  Success = 200,
38  Created = 201,
39  Accepted = 202,
41  NoContent = 204,
42  ResetContent = 205,
43  PartialContent = 206,
44 
45  // Redirection
46  MultipleChoices = 300,
47  MovedPermanently = 301,
48  Found = 302,
49  SeeOther = 303,
50  NotModified = 304,
51  UseProxy = 305,
52  TemporaryRedirect = 307,
53 
54  // Client error
55  BadRequest = 400,
56  Unauthorized = 401,
57  PaymentRequired = 402,
58  Forbidden = 403,
59  NotFound = 404,
60  MethodNotAllowed = 405,
61  NotAcceptable = 406,
63  RequestTimeout = 408,
64  Conflict = 409,
65  Gone = 410,
66  LengthRequired = 411,
67  PreconditionFailed = 412,
69  RequestUriTooLong = 414,
72  ExpectationFailed = 417,
73 
74  // Server error
75  InternalServerError = 500,
76  NotImplemented = 501,
77  BadGateway = 502,
78  ServiceUnavailable = 503,
79  GatewayTimeout = 504,
81  };
82 
83 //=======================================================================================
84 // @bsiclass Bentley Systems
85 //=======================================================================================
87 {
88 private:
89  Utf8String m_url;
90  Utf8String m_authentication;
91  bmap<Utf8String, Utf8String> m_header;
92 public:
93  HttpRequest(Utf8CP url, bmap<Utf8String, Utf8String> const& header) : m_url(url), m_header(header), m_authentication ("") {}
94  Utf8String GetUrl() const {return m_url.c_str();}
95  Utf8String GetAuthentication() const {return m_authentication.c_str();}
96  void SetUrl(Utf8StringCR url) {m_url = url;}
97  void SetAuthentication (Utf8StringCR authentication) {m_authentication = authentication;}
98  bmap<Utf8String, Utf8String> const& GetHeader() const {return m_header;}
99  void SetHeader(bmap<Utf8String, Utf8String> const& header) {m_header = header;}
100 };
101 
102 //=======================================================================================
103 // @remark Required library : DgnPlatform<ApiNumber>.lib i.e. DgnPlatform5.lib
104 // @bsiclass Bentley Systems
105 //=======================================================================================
107 {
108 private:
109  virtual void MakeClassAbstract() = 0;
110 public:
111 public:
112  DGNPLATFORM_EXPORT HttpResponseStatus GetStatus() const;
113  DGNPLATFORM_EXPORT bmap<Utf8String, Utf8String> const& GetHeader() const;
114  DGNPLATFORM_EXPORT bvector<Byte> const& GetBody() const;
115 };
117 
118 //=======================================================================================
119 // @remark Required library : DgnPlatform<ApiNumber>.lib i.e. DgnPlatform5.lib
120 // @bsiclass Bentley Systems
121 //=======================================================================================
123 {
124 friend struct HttpHandler;
125 protected:
127  virtual bool _ShouldCancelHttpRequest() const = 0;
128  virtual void _UpdateProgressInfo (int64_t dltotal, int64_t dlnow, int64_t ultotal, int64_t ulnow) {};
129 };
130 
131 //=======================================================================================
132 // @remark Required library : DgnPlatform<ApiNumber>.lib i.e. DgnPlatform5.lib
133 // @bsiclass Bentley Systems
134 //=======================================================================================
136 {
137 private:
138  virtual void MakeClassAbstract() = 0;
139 public:
140 public:
141  DGNPLATFORM_EXPORT static HttpHandler& Instance();
142  DGNPLATFORM_EXPORT HttpRequestStatus Request(HttpResponsePtr& response, HttpRequest const& request, IHttpRequestCancellationToken const* cancellationToken = nullptr);
143 };
144 
Contains a UTF-8 encoded string.
Definition: WString.h:275
Utf8String GetAuthentication() const
Definition: HttpHandler.h:95
#define END_BENTLEY_DGNPLATFORM_NAMESPACE
Definition: DgnPlatformBaseType.r.h:69
long long int64_t
Definition: Bentley.r.h:94
Utf8String GetUrl() const
Definition: HttpHandler.h:94
virtual ~IHttpRequestCancellationToken()
Definition: HttpHandler.h:126
HttpRequestStatus
Definition: HttpHandler.h:19
bmap< Utf8String, Utf8String > const & GetHeader() const
Definition: HttpHandler.h:98
struct Bentley::Utf8String const & Utf8StringCR
Definition: Bentley.h:241
#define DGNPLATFORM_EXPORT
Definition: DgnPlatform/ExportMacros.h:58
HttpRequest(Utf8CP url, bmap< Utf8String, Utf8String > const &header)
Definition: HttpHandler.h:93
HttpResponseStatus
Definition: HttpHandler.h:32
Definition: HttpHandler.h:106
A shared pointer template for reference-counted objects.
Definition: RefCounted.h:119
Base class to make a class non-copyable.
Definition: NonCopyableClass.h:23
virtual void _UpdateProgressInfo(int64_t dltotal, int64_t dlnow, int64_t ultotal, int64_t ulnow)
Definition: HttpHandler.h:128
#define BEGIN_BENTLEY_DGNPLATFORM_NAMESPACE
Definition: DgnPlatformBaseType.r.h:68
Concrete class that can be used to implement the reference-counting pattern.
Definition: RefCounted.h:109
Definition: HttpRequest.h:26
void SetAuthentication(Utf8StringCR authentication)
Definition: HttpHandler.h:97
Utf8Char const * Utf8CP
Definition: Bentley.h:229
void SetUrl(Utf8StringCR url)
Definition: HttpHandler.h:96
RefCountedPtr< HttpResponse > HttpResponsePtr
Definition: HttpHandler.h:116
void SetHeader(bmap< Utf8String, Utf8String > const &header)
Definition: HttpHandler.h:99
Definition: HttpHandler.h:86
Definition: HttpHandler.h:135
unknown status (newly added to system)

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