HttpResponse.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 <BeHttp/Http.h>
11 #include <Bentley/RefCounted.h>
12 #include <Bentley/WString.h>
13 #include <Bentley/bmap.h>
14 #include "HttpHeaders.h"
15 #include "HttpBody.h"
16 #include "HttpStatus.h"
18 
20 
22 typedef RefCountedPtr<HttpResponseContent> HttpResponseContentPtr;
23 
24 /*--------------------------------------------------------------------------------------+
25 * @bsiclass Bentley Systems
26 +---------------+---------------+---------------+---------------+---------------+------*/
27 enum class ConnectionStatus
28 {
29  None,
30  OK,
31  Canceled,
34  Timeout,
37 };
38 
39 /*--------------------------------------------------------------------------------------+
40 * @bsiclass Bentley Systems
41 +---------------+---------------+---------------+---------------+---------------+------*/
42 struct HttpResponseContent : RefCountedBase
43 {
44 private:
45  HttpResponseHeaders m_headers;
46  HttpBodyPtr m_body;
48 
49 public:
50  static HttpResponseContentPtr Create(HttpBodyPtr responseBody) {return new HttpResponseContent(responseBody);}
51 
52  HttpBodyPtr GetBody() {return m_body;}
53  HttpResponseHeadersR GetHeaders() {return m_headers;}
54  HttpResponseHeadersCR GetHeaders() const {return m_headers;}
55 };
56 
57 /*--------------------------------------------------------------------------------------+
58 * @bsiclass Bentley Systems
59 +---------------+---------------+---------------+---------------+---------------+------*/
60 struct Response
61 {
62 private:
63  Utf8String m_effectiveUrl;
64  HttpStatus m_httpStatus;
65  ConnectionStatus m_connectionStatus;
66  HttpResponseContentPtr m_content;
67 
68 public:
71 
73  BEHTTP_EXPORT Response(HttpResponseContentPtr responseData, Utf8CP effectiveUrl, ConnectionStatus connectionStatus, HttpStatus httpStatus);
74 
75  // Get last used url where response came from
76  Utf8String GetEffectiveUrl() const {return m_effectiveUrl;}
77  HttpBodyCR GetBody() const {return *m_content->GetBody();}
78 
79  HttpResponseHeadersCR GetHeaders() const {return m_content->GetHeaders();}
80  HttpResponseContentPtr GetContent() {return m_content;}
81 
82  ConnectionStatus GetConnectionStatus() const {return m_connectionStatus;}
83  HttpStatus GetHttpStatus() const {return m_httpStatus;}
84 
85  bool IsSuccess() const {if (m_connectionStatus != ConnectionStatus::OK) return false; return HttpStatusHelper::GetType(m_httpStatus) == HttpStatusType::Success;}
86 };
87 
ConnectionStatus GetConnectionStatus() const
Definition: HttpResponse.h:82
RefCountedPtr< HttpResponseContent > HttpResponseContentPtr
Definition: HttpResponse.h:21
HttpBodyCR GetBody() const
Definition: HttpResponse.h:77
#define BEGIN_BENTLEY_HTTP_NAMESPACE
Definition: Http.h:17
bool IsSuccess() const
Definition: HttpResponse.h:85
HttpBodyPtr GetBody()
Definition: HttpResponse.h:52
HttpBody const & HttpBodyCR
Definition: HttpBody.h:18
BEHTTP_EXPORT Response()
Create invalid response with ConnectionStatus::None.
HttpResponseContentPtr GetContent()
Definition: HttpResponse.h:80
Utf8String GetEffectiveUrl() const
Definition: HttpResponse.h:76
#define BEHTTP_EXPORT
Definition: Http.h:14
HttpResponseHeadersCR GetHeaders() const
Definition: HttpResponse.h:54
Definition: HttpResponse.h:42
HttpResponseHeadersR GetHeaders()
Definition: HttpResponse.h:53
HttpStatus
Definition: HttpStatus.h:14
RefCountedPtr< HttpBody > HttpBodyPtr
Definition: HttpBody.h:20
HttpResponseHeadersCR GetHeaders() const
Definition: HttpResponse.h:79
Definition: HttpResponse.h:60
HttpResponseHeaders const & HttpResponseHeadersCR
Definition: HttpHeaders.h:33
Definition: HttpHeaders.h:111
Utf8Char const * Utf8CP
Definition: Bentley.h:229
static BEHTTP_EXPORT HttpStatusType GetType(HttpStatus status)
#define END_BENTLEY_HTTP_NAMESPACE
Definition: Http.h:18
ConnectionStatus
Definition: HttpResponse.h:27
static HttpResponseContentPtr Create(HttpBodyPtr responseBody)
Definition: HttpResponse.h:50
HttpStatus GetHttpStatus() const
Definition: HttpResponse.h:83

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