forked from PowerShell/PowerShell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWebRequestSession.cs
More file actions
109 lines (91 loc) · 3.39 KB
/
Copy pathWebRequestSession.cs
File metadata and controls
109 lines (91 loc) · 3.39 KB
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
/********************************************************************++
Copyright (c) Microsoft Corporation. All rights reserved.
--********************************************************************/
using System;
using System.Net;
using System.Collections.Generic;
using System.Security.Cryptography.X509Certificates;
namespace Microsoft.PowerShell.Commands
{
/// <summary>
/// WebRequestSession for holding session infos.
/// </summary>
public class WebRequestSession
{
/// <summary>
/// gets or sets the Header property
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public Dictionary<string, string> Headers { get; set; }
#if CORECLR
/// <summary>
/// gets or sets the content Headers when using HttpClient
/// </summary>
internal Dictionary<string, string> ContentHeaders { get; set; }
#endif
/// <summary>
/// gets or sets the Cookies property
/// </summary>
public CookieContainer Cookies { get; set; }
#region Credetials
/// <summary>
/// gets or sets the UseDefaultCredentials property
/// </summary>
public bool UseDefaultCredentials { get; set; }
/// <summary>
/// gets or sets the Credentials property
/// </summary>
public ICredentials Credentials { get; set; }
/// <summary>
/// gets or sets the Certificates property
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public X509CertificateCollection Certificates { get; set; }
#endregion
/// <summary>
/// gets or sets the UserAgent property
/// </summary>
public string UserAgent { get; set; }
/// <summary>
/// gets or sets the Proxy property
/// </summary>
public IWebProxy Proxy { get; set; }
/// <summary>
/// gets or sets the RedirectMax property
/// </summary>
public int MaximumRedirection { get; set; }
/// <summary>
/// Construct a new instance of a WebRequestSession object.
/// </summary>
public WebRequestSession()
{
// build the headers collection
Headers = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
#if CORECLR
ContentHeaders = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
#endif
// build the cookie jar
Cookies = new CookieContainer();
// initialize the credential and certificate caches
UseDefaultCredentials = false;
Credentials = null;
Certificates = null;
// setup the default UserAgent
UserAgent = PSUserAgent.UserAgent;
Proxy = null;
MaximumRedirection = -1;
}
/// <summary>
/// Add a X509Certificate to the Certificates collection.
/// </summary>
/// <param name="certificate">The certificate to be added.</param>
internal void AddCertificate(X509Certificate certificate)
{
if (null == Certificates)
{
Certificates = new X509CertificateCollection();
}
Certificates.Add(certificate);
}
}
}