DotNetDupe 4.0.6
C++17/20 Implementation of the .NET Base Class Library (BCL)
Loading...
Searching...
No Matches
HttpResponseMessage.cpp
Go to the documentation of this file.
1#include "pch.h"
4
5namespace DotNetDupe {
6 namespace System {
7 namespace Net {
8 namespace Http {
9
11 : m_statusCode(HttpStatusCode::OK), m_pContent(nullptr) {
13 }
14
16 : m_statusCode(statusCode), m_pContent(nullptr) {
18 }
19
22 return m_statusCode;
23 }
24
27 m_statusCode = statusCode;
28 }
29
32 return m_sReasonPhrase;
33 }
34
35 void HttpResponseMessage::SetReasonPhrase(const String& reasonPhrase) {
37 m_sReasonPhrase = reasonPhrase;
38 }
39
42 int code = static_cast<int>(m_statusCode);
43 return code >= 200 && code <= 299;
44 }
45
48 return m_pContent;
49 }
50
53 m_pContent = content;
54 }
55
60
65
68 if (IsSuccessStatusCode()) {
69 return;
70 }
72 std::string msg = "Response status code does not indicate success: ";
73 msg += std::to_string(static_cast<int>(m_statusCode));
74 if (!m_sReasonPhrase.IsEmpty()) {
75 msg += " (";
76 msg += m_sReasonPhrase.GetRawString();
77 msg += ")";
78 }
79 msg += ".";
81 throw HttpRequestException(msg.c_str());
82 }
83
84 }
85 }
86 }
87}
Exception thrown when an HTTP request or connection failure occurs.
Represents an HTTP response message adhering to RFC 9110 and RFC 9112.
Represents a collection of keys and values.
Definition Dictionary.h:66
HttpRequestException(const String &sMessage)
Initializes a new instance of the HttpRequestException class with a specified error message.
void SetContent(const HttpContentPtr &content)
Sets the content of the HTTP response message.
HttpStatusCode GetStatusCode() const
Gets the status code of the HTTP response.
String GetReasonPhrase() const
Gets the reason phrase which typically accompanies the status code.
void SetReasonPhrase(const String &reasonPhrase)
Sets the reason phrase which typically accompanies the status code.
void EnsureSuccessStatusCode()
Throws an HttpRequestException if IsSuccessStatusCode() is false.
void SetStatusCode(HttpStatusCode statusCode)
Sets the status code of the HTTP response.
HttpContentPtr GetContent() const
Gets the content of the HTTP response message.
bool IsSuccessStatusCode() const
Gets a value that indicates if the HTTP response was successful (status in range 200-299).
HttpResponseMessage()
Initializes a new instance of the HttpResponseMessage class with OK (200) status.
Collections::Generic::Dictionary< String, String > & GetHeaders()
Gets the collection of HTTP response headers.
Represents text as a sequence of UTF-8 code units with culture-invariant operations.
Definition String.h:74
SmartPointer< HttpContent > HttpContentPtr
Type alias for reference-counted SmartPointer to HttpContent.
Definition HttpContent.h:66
HttpStatusCode
Contains the values of status codes defined for HTTP in RFC 9110 and RFC 7231.
@ OK
Equivalent to HTTP status 200. Indicates that the request succeeded.