forked from PowerShell/PowerShell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWebResponseObject.Common.cs
More file actions
99 lines (84 loc) · 2.9 KB
/
Copy pathWebResponseObject.Common.cs
File metadata and controls
99 lines (84 loc) · 2.9 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
/********************************************************************++
Copyright (c) Microsoft Corporation. All rights reserved.
--********************************************************************/
using System;
using System.Diagnostics.CodeAnalysis;
using System.IO;
namespace Microsoft.PowerShell.Commands
{
/// <summary>
/// WebResponseObject
/// </summary>
public partial class WebResponseObject
{
#region Properties
/// <summary>
/// gets or protected sets the Content property
/// </summary>
[SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")]
public byte[] Content { get; protected set; }
/// <summary>
/// gets the StatusCode property
/// </summary>
public int StatusCode
{
get { return (WebResponseHelper.GetStatusCode(BaseResponse)); }
}
/// <summary>
/// gets the StatusDescription property
/// </summary>
public string StatusDescription
{
get { return (WebResponseHelper.GetStatusDescription(BaseResponse)); }
}
private MemoryStream _rawContentStream;
/// <summary>
/// gets the RawContentStream property
/// </summary>
public MemoryStream RawContentStream
{
get { return (_rawContentStream); }
}
/// <summary>
/// gets the RawContentLength property
/// </summary>
public long RawContentLength
{
get { return (null == RawContentStream ? -1 : RawContentStream.Length); }
}
/// <summary>
/// gets or protected sets the RawContent property
/// </summary>
public string RawContent { get; protected set; }
#endregion Properties
#region Methods
/// <summary>
/// Reads the response content from the web response.
/// </summary>
private void InitializeContent()
{
this.Content = this.RawContentStream.ToArray();
}
private bool IsPrintable(char c)
{
return (Char.IsLetterOrDigit(c) || Char.IsPunctuation(c) || Char.IsSeparator(c) || Char.IsSymbol(c) || Char.IsWhiteSpace(c));
}
/// <summary>
/// Returns the string representation of this web response.
/// </summary>
/// <returns>The string representation of this web response.</returns>
public sealed override string ToString()
{
char[] stringContent = System.Text.Encoding.ASCII.GetChars(Content);
for (int counter = 0; counter < stringContent.Length; counter++)
{
if (!IsPrintable(stringContent[counter]))
{
stringContent[counter] = '.';
}
}
return new string(stringContent);
}
#endregion Methods
}
}