@@ -35,24 +35,18 @@ internal SessionEventArgs(int bufferSize)
35
35
ProxySession = new HttpWebSession ( ) ;
36
36
}
37
37
38
- public Client Client { get ; set ; }
38
+ internal Client Client { get ; set ; }
39
39
40
40
public bool IsHttps { get ; internal set ; }
41
41
42
42
public HttpWebSession ProxySession { get ; set ; }
43
43
44
44
45
-
46
45
public int RequestContentLength
47
46
{
48
47
get
49
48
{
50
- if ( ProxySession . Request . RequestHeaders . All ( x => x . Name . ToLower ( ) != "content-length" ) ) return - 1 ;
51
- int contentLen ;
52
- int . TryParse ( ProxySession . Request . RequestHeaders . First ( x => x . Name . ToLower ( ) == "content-length" ) . Value , out contentLen ) ;
53
- if ( contentLen != 0 )
54
- return contentLen ;
55
- return - 1 ;
49
+ return ProxySession . Request . ContentLength ;
56
50
}
57
51
}
58
52
@@ -71,9 +65,7 @@ public string ResponseContentType
71
65
{
72
66
get
73
67
{
74
- return ProxySession . Response . ResponseHeaders . Any ( x => x . Name . ToLower ( ) == "content-type" )
75
- ? ProxySession . Response . ResponseHeaders . First ( x => x . Name . ToLower ( ) == "content-type" ) . Value
76
- : null ;
68
+ return ProxySession . Response . ContentType ;
77
69
}
78
70
}
79
71
@@ -201,7 +193,7 @@ private void ReadResponseBody()
201
193
responseBodyStream . Write ( buffer , 0 , buffer . Length ) ;
202
194
}
203
195
204
- switch ( ProxySession . Response . ResponseContentEncoding )
196
+ switch ( ProxySession . Response . ContentEncoding )
205
197
{
206
198
case "gzip" :
207
199
ProxySession . Response . ResponseBody = CompressionHelper . DecompressGzip ( responseBodyStream . ToArray ( ) ) ;
@@ -223,12 +215,11 @@ private void ReadResponseBody()
223
215
}
224
216
225
217
226
-
227
218
public Encoding GetRequestBodyEncoding ( )
228
219
{
229
220
if ( ProxySession . Request . RequestLocked ) throw new Exception ( "You cannot call this function after request is made to server." ) ;
230
221
231
- return ProxySession . Request . RequestEncoding ;
222
+ return ProxySession . Request . Encoding ;
232
223
}
233
224
234
225
public byte [ ] GetRequestBody ( )
@@ -246,7 +237,7 @@ public string GetRequestBodyAsString()
246
237
247
238
ReadRequestBody ( ) ;
248
239
249
- return ProxySession . Request . RequestBodyString ?? ( ProxySession . Request . RequestBodyString = ProxySession . Request . RequestEncoding . GetString ( ProxySession . Request . RequestBody ) ) ;
240
+ return ProxySession . Request . RequestBodyString ?? ( ProxySession . Request . RequestBodyString = ProxySession . Request . Encoding . GetString ( ProxySession . Request . RequestBody ) ) ;
250
241
}
251
242
252
243
public void SetRequestBody ( byte [ ] body )
@@ -271,15 +262,15 @@ public void SetRequestBodyString(string body)
271
262
ReadRequestBody ( ) ;
272
263
}
273
264
274
- ProxySession . Request . RequestBody = ProxySession . Request . RequestEncoding . GetBytes ( body ) ;
265
+ ProxySession . Request . RequestBody = ProxySession . Request . Encoding . GetBytes ( body ) ;
275
266
ProxySession . Request . RequestBodyRead = true ;
276
267
}
277
268
278
269
public Encoding GetResponseBodyEncoding ( )
279
270
{
280
271
if ( ! ProxySession . Request . RequestLocked ) throw new Exception ( "You cannot call this function before request is made to server." ) ;
281
272
282
- return ProxySession . Response . ResponseEncoding ;
273
+ return ProxySession . Response . Encoding ;
283
274
}
284
275
285
276
public byte [ ] GetResponseBody ( )
@@ -296,7 +287,7 @@ public string GetResponseBodyAsString()
296
287
297
288
GetResponseBody ( ) ;
298
289
299
- return ProxySession . Response . ResponseBodyString ?? ( ProxySession . Response . ResponseBodyString = ProxySession . Response . ResponseEncoding . GetString ( ProxySession . Response . ResponseBody ) ) ;
290
+ return ProxySession . Response . ResponseBodyString ?? ( ProxySession . Response . ResponseBodyString = ProxySession . Response . Encoding . GetString ( ProxySession . Response . ResponseBody ) ) ;
300
291
}
301
292
302
293
public void SetResponseBody ( byte [ ] body )
@@ -320,7 +311,7 @@ public void SetResponseBodyString(string body)
320
311
GetResponseBody ( ) ;
321
312
}
322
313
323
- var bodyBytes = ProxySession . Response . ResponseEncoding . GetBytes ( body ) ;
314
+ var bodyBytes = ProxySession . Response . Encoding . GetBytes ( body ) ;
324
315
SetResponseBody ( bodyBytes ) ;
325
316
}
326
317
@@ -335,22 +326,20 @@ public void Ok(string html)
335
326
var result = Encoding . Default . GetBytes ( html ) ;
336
327
337
328
var connectStreamWriter = new StreamWriter ( this . Client . ClientStream ) ;
338
- var s = string . Format ( "HTTP/{0}.{1} {2} {3}" , ProxySession . Request . RequestHttpVersion . Major , ProxySession . Request . RequestHttpVersion . Minor , 200 , "Ok" ) ;
339
- connectStreamWriter . WriteLine ( s ) ;
329
+ connectStreamWriter . WriteLine ( string . Format ( "{0} {2} {3}" , ProxySession . Request . HttpVersion , 200 , "Ok" ) ) ;
340
330
connectStreamWriter . WriteLine ( "Timestamp: {0}" , DateTime . Now ) ;
341
331
connectStreamWriter . WriteLine ( "content-length: " + result . Length ) ;
342
332
connectStreamWriter . WriteLine ( "Cache-Control: no-cache, no-store, must-revalidate" ) ;
343
333
connectStreamWriter . WriteLine ( "Pragma: no-cache" ) ;
344
334
connectStreamWriter . WriteLine ( "Expires: 0" ) ;
345
335
346
- connectStreamWriter . WriteLine ( ProxySession . Request . RequestIsAlive ? "Connection: Keep-Alive" : "Connection: close" ) ;
336
+ connectStreamWriter . WriteLine ( ProxySession . Request . IsAlive ? "Connection: Keep-Alive" : "Connection: close" ) ;
347
337
348
338
connectStreamWriter . WriteLine ( ) ;
349
339
connectStreamWriter . Flush ( ) ;
350
340
351
341
this . Client . ClientStream . Write ( result , 0 , result . Length ) ;
352
342
353
-
354
343
ProxySession . Request . CancelRequest = true ;
355
344
}
356
345
}
0 commit comments