-
Notifications
You must be signed in to change notification settings - Fork 0
/
HttpRequest.cs
109 lines (90 loc) · 3.94 KB
/
HttpRequest.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
using System;
using System.Net;
namespace Dell.Premier.Web.Common.HttpClient
{
/// <summary>HttpRequest represents an HTTP request.</summary>
public class HttpRequest
{
private readonly HttpHeaders _headers = new HttpHeaders();
/// <summary>Initializes a new instance of <see cref="HttpRequest" />.</summary>
public HttpRequest()
{
}
/// <summary>
/// Initializes a new instance of <see cref="HttpRequest" /> by copying the header values from
/// <paramref name="headers" />.
/// </summary>
/// <exception cref="ArgumentNullException">Thrown when <paramref name="headers" /> is null.</exception>
/// <param name="headers">The <see cref="HttpHeaders" /> to copy into this <see cref="HttpRequest" />.</param>
public HttpRequest(HttpHeaders headers)
{
if (headers == null)
throw new ArgumentNullException(nameof(headers));
foreach (var header in headers)
{
Headers.Add(header.Field, header.Value);
}
}
/// <summary>Initializes a new instance of <see cref="HttpRequest" />.</summary>
/// <exception cref="ArgumentNullException">
/// Thrown when <paramref name="method" /> or <paramref name="url" /> arguments are null.
/// </exception>
/// <param name="method">The HTTP method.</param>
/// <param name="url">URL of the document.</param>
public HttpRequest(string method, string url)
{
if (method == null)
throw new ArgumentNullException(nameof(method));
if (url == null)
throw new ArgumentNullException(nameof(url));
Method = method;
Uri = new Uri(url);
}
/// <summary>
/// Initializes a new instance of <see cref="HttpRequest" /> by creating a copy of the specified
/// <paramref name="request" />.
/// </summary>
/// <param name="request">The request to copy; can be null.</param>
public HttpRequest(HttpRequest request)
{
if (request == null)
return;
Uri = request.Uri;
Method = request.Method;
Body = request.Body;
Timeout = request.Timeout;
Proxy = request.Proxy;
Credentials = request.Credentials;
DisableCompression = request.DisableCompression;
DisableKeepAlive = request.DisableKeepAlive;
DisableAutoRedirect = request.DisableAutoRedirect;
foreach (var header in request.Headers)
{
Headers.Add(header.Field, header.Value);
}
}
/// <summary>Gets or sets the request body.</summary>
public byte[] Body { get; set; }
/// <summary>Gets or sets the credentials.</summary>
public ICredentials Credentials { get; set; }
/// <summary>Gets or sets a value indicating whether automatic redirect is disabled.</summary>
public bool DisableAutoRedirect { get; set; }
/// <summary>Gets or sets a value indicating whether Gzip compression is disabled.</summary>
public bool DisableCompression { get; set; }
/// <summary>Gets or sets a value indicating whether keep-alive is disabled.</summary>
public bool DisableKeepAlive { get; set; }
/// <summary>Gets the HTTP headers for this request.</summary>
public HttpHeaders Headers
{
get { return _headers; }
}
/// <summary>Gets or sets the HTTP method.</summary>
public string Method { get; set; }
/// <summary>Gets or sets the proxy.</summary>
public IWebProxy Proxy { get; set; }
/// <summary>Gets or sets the timeout.</summary>
public TimeSpan? Timeout { get; set; }
/// <summary>Gets or sets the request URI.</summary>
public Uri Uri { get; set; }
}
}