-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWSSWebResponse.cs
138 lines (125 loc) · 4.01 KB
/
WSSWebResponse.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
namespace WebServiceStudio
{
using System;
using System.IO;
using System.Net;
using System.Text;
public class WSSWebResponse : WebResponse
{
private MemoryStream stream;
private WebResponse webResponse;
public WSSWebResponse(WebResponse webResponse)
{
this.webResponse = webResponse;
this.stream = new NoCloseMemoryStream();
Stream responseStream = webResponse.GetResponseStream();
byte[] buffer = new byte[0x400];
while (true)
{
int count = responseStream.Read(buffer, 0, buffer.Length);
if (count <= 0)
{
break;
}
this.stream.Write(buffer, 0, count);
}
this.stream.Position = 0L;
}
public override void Close()
{
this.webResponse.Close();
}
public string DumpResponse()
{
long position = this.stream.Position;
this.stream.Position = 0L;
string str = DumpResponse(this);
this.stream.Position = position;
return str;
}
public static string DumpResponse(WebResponse response)
{
Stream responseStream = response.GetResponseStream();
StringBuilder builder = new StringBuilder();
if (response is HttpWebResponse)
{
HttpWebResponse response2 = (HttpWebResponse) response;
builder.Append(string.Concat(new object[] { "ResponseCode: ", (int) response2.StatusCode, " (", response2.StatusDescription, ")\n" }));
}
else if (response is WSSWebResponse)
{
WSSWebResponse response3 = (WSSWebResponse) response;
builder.Append(string.Concat(new object[] { "ResponseCode: ", (int) response3.StatusCode, " (", response3.StatusDescription, ")\n" }));
}
foreach (string str in response.Headers.Keys)
{
builder.Append(str + ":" + response.Headers[str].ToString() + "\n");
}
builder.Append("\n");
builder.Append(MessageTracer.ReadMessage(responseStream, (int) response.ContentLength, response.ContentType));
return builder.ToString();
}
public override Stream GetResponseStream()
{
return this.stream;
}
public override long ContentLength
{
get
{
return this.webResponse.ContentLength;
}
set
{
this.webResponse.ContentLength = value;
}
}
public override string ContentType
{
get
{
return this.webResponse.ContentType;
}
set
{
this.webResponse.ContentType = value;
}
}
public override WebHeaderCollection Headers
{
get
{
return this.webResponse.Headers;
}
}
public override Uri ResponseUri
{
get
{
return this.webResponse.ResponseUri;
}
}
public HttpStatusCode StatusCode
{
get
{
if (this.webResponse is HttpWebResponse)
{
return ((HttpWebResponse) this.webResponse).StatusCode;
}
return HttpStatusCode.NotImplemented;
}
}
public string StatusDescription
{
get
{
if (this.webResponse is HttpWebResponse)
{
return ((HttpWebResponse) this.webResponse).StatusDescription;
}
return "";
}
}
}
}