-
Notifications
You must be signed in to change notification settings - Fork 0
/
HttpResponse.cs
87 lines (77 loc) · 2.86 KB
/
HttpResponse.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
using System;
using System.Net;
namespace Dell.Premier.Web.Common.HttpClient
{
/// <summary>HttpResponse represents an HTTP response.</summary>
public class HttpResponse
{
private readonly byte[] _body;
private readonly Exception _exception;
private readonly HttpHeaders _headers;
private readonly HttpRequest _request;
private readonly HttpStatusCode _status;
private readonly bool _uncompressed;
public HttpResponse(
HttpStatusCode status,
HttpHeaders headers,
byte[] body,
bool uncompressed,
HttpRequest request,
Exception exception
)
{
if (request == null)
throw new ArgumentNullException(nameof(request));
_status = status;
_headers = headers ?? new HttpHeaders();
_body = body ?? new byte[0];
_uncompressed = uncompressed;
_request = request;
_exception = exception;
}
/// <summary>Gets the body in bytes. This property is never <c>null</c>.</summary>
internal byte[] Body
{
get { return _body; }
}
/// <summary>Gets the exception, if any.</summary>
public Exception Exception
{
get { return _exception; }
}
/// <summary>Gets the HTTP response headers. This property is never null, though it may be empty.</summary>
public HttpHeaders Headers
{
get { return _headers; }
}
/// <summary>Gets the HTTP request sent to the server. This property is never null.</summary>
public HttpRequest Request
{
get { return _request; }
}
/// <summary>Gets the HTTP status code.</summary>
public HttpStatusCode Status
{
get { return _status; }
}
/// <summary>
/// Success indicates whether the request has an HTTP <see cref="Status" /> in the 2xx range and
/// encountered no other exceptions. Check this property before calling
/// <see cref="HttpResponseExtensions.Read{T}" /> or
/// <see cref="HttpResponseExtensions.ReadError{T}" />.
/// </summary>
public bool Success
{
get { return (int)Status >= 200 && (int)Status <= 299 && Exception == null; }
}
/// <summary>
/// Gets a value indicating whether the response was uncompressed by the <see cref="WebApiClient" />.
/// To disable gzip handling in <see cref="WebApiClient" />, set <see cref="HttpRequest.DisableCompression" />
/// to true or set the <see cref="HttpRequest.Headers" /> "Accept-Encoding" header value.
/// </summary>
public bool Uncompressed
{
get { return _uncompressed; }
}
}
}