299 lines
7.5 KiB
C#
299 lines
7.5 KiB
C#
using System;
|
|
using System.IO;
|
|
using System.Runtime.InteropServices;
|
|
using System.Text;
|
|
|
|
namespace System.Net
|
|
{
|
|
// Token: 0x02000251 RID: 593
|
|
internal class ResponseStream : Stream
|
|
{
|
|
// Token: 0x06001505 RID: 5381 RVA: 0x000433AC File Offset: 0x000415AC
|
|
internal ResponseStream(Stream stream, HttpListenerResponse response, bool ignore_errors)
|
|
{
|
|
this.response = response;
|
|
this.ignore_errors = ignore_errors;
|
|
this.stream = stream;
|
|
}
|
|
|
|
// Token: 0x170006DC RID: 1756
|
|
// (get) Token: 0x06001507 RID: 5383 RVA: 0x000433E4 File Offset: 0x000415E4
|
|
public override bool CanRead
|
|
{
|
|
get
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
// Token: 0x170006DD RID: 1757
|
|
// (get) Token: 0x06001508 RID: 5384 RVA: 0x000433E8 File Offset: 0x000415E8
|
|
public override bool CanSeek
|
|
{
|
|
get
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
// Token: 0x170006DE RID: 1758
|
|
// (get) Token: 0x06001509 RID: 5385 RVA: 0x000433EC File Offset: 0x000415EC
|
|
public override bool CanWrite
|
|
{
|
|
get
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
|
|
// Token: 0x170006DF RID: 1759
|
|
// (get) Token: 0x0600150A RID: 5386 RVA: 0x000433F0 File Offset: 0x000415F0
|
|
public override long Length
|
|
{
|
|
get
|
|
{
|
|
throw new NotSupportedException();
|
|
}
|
|
}
|
|
|
|
// Token: 0x170006E0 RID: 1760
|
|
// (get) Token: 0x0600150B RID: 5387 RVA: 0x000433F8 File Offset: 0x000415F8
|
|
// (set) Token: 0x0600150C RID: 5388 RVA: 0x00043400 File Offset: 0x00041600
|
|
public override long Position
|
|
{
|
|
get
|
|
{
|
|
throw new NotSupportedException();
|
|
}
|
|
set
|
|
{
|
|
throw new NotSupportedException();
|
|
}
|
|
}
|
|
|
|
// Token: 0x0600150D RID: 5389 RVA: 0x00043408 File Offset: 0x00041608
|
|
public override void Close()
|
|
{
|
|
if (!this.disposed)
|
|
{
|
|
this.disposed = true;
|
|
MemoryStream headers = this.GetHeaders(true);
|
|
bool sendChunked = this.response.SendChunked;
|
|
if (headers != null)
|
|
{
|
|
long position = headers.Position;
|
|
if (sendChunked && !this.trailer_sent)
|
|
{
|
|
byte[] array = ResponseStream.GetChunkSizeBytes(0, true);
|
|
headers.Position = headers.Length;
|
|
headers.Write(array, 0, array.Length);
|
|
}
|
|
this.InternalWrite(headers.GetBuffer(), (int)position, (int)(headers.Length - position));
|
|
this.trailer_sent = true;
|
|
}
|
|
else if (sendChunked && !this.trailer_sent)
|
|
{
|
|
byte[] array = ResponseStream.GetChunkSizeBytes(0, true);
|
|
this.InternalWrite(array, 0, array.Length);
|
|
this.trailer_sent = true;
|
|
}
|
|
this.response.Close();
|
|
}
|
|
}
|
|
|
|
// Token: 0x0600150E RID: 5390 RVA: 0x000434D4 File Offset: 0x000416D4
|
|
private MemoryStream GetHeaders(bool closing)
|
|
{
|
|
if (this.response.HeadersSent)
|
|
{
|
|
return null;
|
|
}
|
|
MemoryStream memoryStream = new MemoryStream();
|
|
this.response.SendHeaders(closing, memoryStream);
|
|
return memoryStream;
|
|
}
|
|
|
|
// Token: 0x0600150F RID: 5391 RVA: 0x00043508 File Offset: 0x00041708
|
|
public override void Flush()
|
|
{
|
|
}
|
|
|
|
// Token: 0x06001510 RID: 5392 RVA: 0x0004350C File Offset: 0x0004170C
|
|
private static byte[] GetChunkSizeBytes(int size, bool final)
|
|
{
|
|
string text = string.Format("{0:x}\r\n{1}", size, (!final) ? string.Empty : "\r\n");
|
|
return Encoding.ASCII.GetBytes(text);
|
|
}
|
|
|
|
// Token: 0x06001511 RID: 5393 RVA: 0x0004354C File Offset: 0x0004174C
|
|
internal void InternalWrite(byte[] buffer, int offset, int count)
|
|
{
|
|
if (this.ignore_errors)
|
|
{
|
|
try
|
|
{
|
|
this.stream.Write(buffer, offset, count);
|
|
}
|
|
catch
|
|
{
|
|
}
|
|
}
|
|
else
|
|
{
|
|
this.stream.Write(buffer, offset, count);
|
|
}
|
|
}
|
|
|
|
// Token: 0x06001512 RID: 5394 RVA: 0x000435AC File Offset: 0x000417AC
|
|
public override void Write(byte[] buffer, int offset, int count)
|
|
{
|
|
if (this.disposed)
|
|
{
|
|
throw new ObjectDisposedException(base.GetType().ToString());
|
|
}
|
|
MemoryStream headers = this.GetHeaders(false);
|
|
bool sendChunked = this.response.SendChunked;
|
|
if (headers != null)
|
|
{
|
|
long position = headers.Position;
|
|
headers.Position = headers.Length;
|
|
if (sendChunked)
|
|
{
|
|
byte[] array = ResponseStream.GetChunkSizeBytes(count, false);
|
|
headers.Write(array, 0, array.Length);
|
|
}
|
|
int num = Math.Min(count, 16384 - (int)headers.Position + (int)position);
|
|
headers.Write(buffer, offset, num);
|
|
count -= num;
|
|
offset += num;
|
|
this.InternalWrite(headers.GetBuffer(), (int)position, (int)(headers.Length - position));
|
|
headers.SetLength(0L);
|
|
headers.Capacity = 0;
|
|
}
|
|
else if (sendChunked)
|
|
{
|
|
byte[] array = ResponseStream.GetChunkSizeBytes(count, false);
|
|
this.InternalWrite(array, 0, array.Length);
|
|
}
|
|
if (count > 0)
|
|
{
|
|
this.InternalWrite(buffer, offset, count);
|
|
}
|
|
if (sendChunked)
|
|
{
|
|
this.InternalWrite(ResponseStream.crlf, 0, 2);
|
|
}
|
|
}
|
|
|
|
// Token: 0x06001513 RID: 5395 RVA: 0x000436B4 File Offset: 0x000418B4
|
|
public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback cback, object state)
|
|
{
|
|
if (this.disposed)
|
|
{
|
|
throw new ObjectDisposedException(base.GetType().ToString());
|
|
}
|
|
MemoryStream headers = this.GetHeaders(false);
|
|
bool sendChunked = this.response.SendChunked;
|
|
if (headers != null)
|
|
{
|
|
long position = headers.Position;
|
|
headers.Position = headers.Length;
|
|
if (sendChunked)
|
|
{
|
|
byte[] array = ResponseStream.GetChunkSizeBytes(count, false);
|
|
headers.Write(array, 0, array.Length);
|
|
}
|
|
headers.Write(buffer, offset, count);
|
|
buffer = headers.GetBuffer();
|
|
offset = (int)position;
|
|
count = (int)(headers.Position - position);
|
|
}
|
|
else if (sendChunked)
|
|
{
|
|
byte[] array = ResponseStream.GetChunkSizeBytes(count, false);
|
|
this.InternalWrite(array, 0, array.Length);
|
|
}
|
|
return this.stream.BeginWrite(buffer, offset, count, cback, state);
|
|
}
|
|
|
|
// Token: 0x06001514 RID: 5396 RVA: 0x00043778 File Offset: 0x00041978
|
|
public override void EndWrite(IAsyncResult ares)
|
|
{
|
|
if (this.disposed)
|
|
{
|
|
throw new ObjectDisposedException(base.GetType().ToString());
|
|
}
|
|
if (this.ignore_errors)
|
|
{
|
|
try
|
|
{
|
|
this.stream.EndWrite(ares);
|
|
if (this.response.SendChunked)
|
|
{
|
|
this.stream.Write(ResponseStream.crlf, 0, 2);
|
|
}
|
|
}
|
|
catch
|
|
{
|
|
}
|
|
}
|
|
else
|
|
{
|
|
this.stream.EndWrite(ares);
|
|
if (this.response.SendChunked)
|
|
{
|
|
this.stream.Write(ResponseStream.crlf, 0, 2);
|
|
}
|
|
}
|
|
}
|
|
|
|
// Token: 0x06001515 RID: 5397 RVA: 0x00043834 File Offset: 0x00041A34
|
|
public override int Read([In] [Out] byte[] buffer, int offset, int count)
|
|
{
|
|
throw new NotSupportedException();
|
|
}
|
|
|
|
// Token: 0x06001516 RID: 5398 RVA: 0x0004383C File Offset: 0x00041A3C
|
|
public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback cback, object state)
|
|
{
|
|
throw new NotSupportedException();
|
|
}
|
|
|
|
// Token: 0x06001517 RID: 5399 RVA: 0x00043844 File Offset: 0x00041A44
|
|
public override int EndRead(IAsyncResult ares)
|
|
{
|
|
throw new NotSupportedException();
|
|
}
|
|
|
|
// Token: 0x06001518 RID: 5400 RVA: 0x0004384C File Offset: 0x00041A4C
|
|
public override long Seek(long offset, SeekOrigin origin)
|
|
{
|
|
throw new NotSupportedException();
|
|
}
|
|
|
|
// Token: 0x06001519 RID: 5401 RVA: 0x00043854 File Offset: 0x00041A54
|
|
public override void SetLength(long value)
|
|
{
|
|
throw new NotSupportedException();
|
|
}
|
|
|
|
// Token: 0x040011A5 RID: 4517
|
|
private HttpListenerResponse response;
|
|
|
|
// Token: 0x040011A6 RID: 4518
|
|
private bool ignore_errors;
|
|
|
|
// Token: 0x040011A7 RID: 4519
|
|
private bool disposed;
|
|
|
|
// Token: 0x040011A8 RID: 4520
|
|
private bool trailer_sent;
|
|
|
|
// Token: 0x040011A9 RID: 4521
|
|
private Stream stream;
|
|
|
|
// Token: 0x040011AA RID: 4522
|
|
private static byte[] crlf = new byte[] { 13, 10 };
|
|
}
|
|
}
|