internal void SendRequest(IMessage msg, ITransportHeaders headers, Stream contentStream) { IMethodCallMessage message = (IMethodCallMessage) msg; int length = (int) contentStream.Length; string uri = message.Uri; this._bOneWayRequest = RemotingServices.IsOneWay(message.MethodBase); ChunkedMemoryStream outputStream = new ChunkedMemoryStream(CoreChannel.BufferPool); base.WritePreambleAndVersion(outputStream); if (!this._bOneWayRequest) { base.WriteUInt16(0, outputStream); } else { base.WriteUInt16(1, outputStream); } base.WriteUInt16(0, outputStream); base.WriteInt32(length, outputStream); base.WriteUInt16(4, outputStream); base.WriteByte(1, outputStream); base.WriteCountedString(uri, outputStream); base.WriteHeaders(headers, outputStream); outputStream.WriteTo(base.NetStream); outputStream.Close(); StreamHelper.CopyStream(contentStream, base.NetStream); contentStream.Close(); }
internal static void CopyStream(Stream source, Stream target) { if (source != null) { ChunkedMemoryStream stream = source as ChunkedMemoryStream; if (stream != null) { stream.WriteTo(target); } else { MemoryStream stream2 = source as MemoryStream; if (stream2 != null) { stream2.WriteTo(target); } else { byte[] buffer = CoreChannel.BufferPool.GetBuffer(); int length = buffer.Length; for (int i = source.Read(buffer, 0, length); i > 0; i = source.Read(buffer, 0, length)) { target.Write(buffer, 0, i); } CoreChannel.BufferPool.ReturnBuffer(buffer); } } } }
public Stream GetRequestStream(IMessage msg, int contentLength, ITransportHeaders headers) { IMethodCallMessage message = (IMethodCallMessage) msg; string uri = message.Uri; this._bOneWayRequest = RemotingServices.IsOneWay(message.MethodBase); ChunkedMemoryStream outputStream = new ChunkedMemoryStream(CoreChannel.BufferPool); base.WritePreambleAndVersion(outputStream); if (!this._bOneWayRequest) { base.WriteUInt16(0, outputStream); } else { base.WriteUInt16(1, outputStream); } base.WriteUInt16(0, outputStream); base.WriteInt32(contentLength, outputStream); base.WriteUInt16(4, outputStream); base.WriteByte(1, outputStream); base.WriteCountedString(uri, outputStream); base.WriteHeaders(headers, outputStream); outputStream.WriteTo(base.NetStream); outputStream.Close(); this._requestStream = base.NetStream; return this._requestStream; }
internal static void CopyStream(Stream source, Stream target) { if (source == null) { return; } // see if this is a ChunkedMemoryStream (we can do a direct write) ChunkedMemoryStream chunkedMemStream = source as ChunkedMemoryStream; if (chunkedMemStream != null) { chunkedMemStream.WriteTo(target); } else { // see if this is a MemoryStream (we can do a direct write) MemoryStream memContentStream = source as MemoryStream; if (memContentStream != null) { memContentStream.WriteTo(target); } else { // otherwise, we need to copy the data through an intermediate buffer byte[] buffer = CoreChannel.BufferPool.GetBuffer(); int bufferSize = buffer.Length; int readCount = source.Read(buffer, 0, bufferSize); while (readCount > 0) { target.Write(buffer, 0, readCount); readCount = source.Read(buffer, 0, bufferSize); } CoreChannel.BufferPool.ReturnBuffer(buffer); } } } // CopyStream
public Stream GetResponseStream(string statusCode, string reasonPhrase, ITransportHeaders headers) { bool flag = false; bool flag2 = false; int length = 0; object obj2 = headers["__HttpStatusCode"]; string str = headers["__HttpReasonPhrase"] as string; if (obj2 != null) { statusCode = obj2.ToString(); } if (str != null) { reasonPhrase = str; } if (!this.CanServiceAnotherRequest()) { headers["Connection"] = "Close"; } object obj3 = headers["Content-Length"]; if (obj3 != null) { flag = true; if (obj3 is int) { length = (int) obj3; } else { length = Convert.ToInt32(obj3, CultureInfo.InvariantCulture); } } flag2 = this.AllowChunkedResponse && !flag; if (flag2) { headers["Transfer-Encoding"] = "chunked"; } ChunkedMemoryStream outputStream = new ChunkedMemoryStream(CoreChannel.BufferPool); base.WriteResponseFirstLine(statusCode, reasonPhrase, outputStream); base.WriteHeaders(headers, outputStream); outputStream.WriteTo(base.NetStream); outputStream.Close(); if (flag2) { this._responseStream = new HttpChunkedResponseStream(base.NetStream); } else { this._responseStream = new HttpFixedLengthResponseStream(base.NetStream, length); } return this._responseStream; }
} // GetRequestStream public Stream GetResponseStream(String statusCode, String reasonPhrase, ITransportHeaders headers) { bool contentLengthPresent = false; bool useChunkedEncoding = false; int contentLength = 0; // check for custom user status code and reason phrase Object userStatusCode = headers["__HttpStatusCode"]; // someone might have stored an int String userReasonPhrase = headers["__HttpReasonPhrase"] as String; if (userStatusCode != null) statusCode = userStatusCode.ToString(); if (userReasonPhrase != null) reasonPhrase = userReasonPhrase; // see if we can handle any more requests on this socket if (!CanServiceAnotherRequest()) { headers["Connection"] = "Close"; } // check for content length Object contentLengthEntry = headers["Content-Length"]; if (contentLengthEntry != null) { contentLengthPresent = true; if (contentLengthEntry is int) contentLength = (int)contentLengthEntry; else contentLength = Convert.ToInt32(contentLengthEntry, CultureInfo.InvariantCulture); } // see if we are going to use chunked-encoding useChunkedEncoding = AllowChunkedResponse && !contentLengthPresent; if (useChunkedEncoding) headers["Transfer-Encoding"] = "chunked"; // write headers to stream ChunkedMemoryStream headerStream = new ChunkedMemoryStream(CoreChannel.BufferPool); WriteResponseFirstLine(statusCode, reasonPhrase, headerStream); WriteHeaders(headers, headerStream); headerStream.WriteTo(NetStream); headerStream.Close(); // return stream ready for content if (useChunkedEncoding) _responseStream = new HttpChunkedResponseStream(NetStream); else _responseStream = new HttpFixedLengthResponseStream(NetStream, contentLength); return _responseStream; } // GetResponseStream
public void SendResponse(ITransportHeaders headers, Stream contentStream) { if (!this._bOneWayRequest) { ChunkedMemoryStream outputStream = new ChunkedMemoryStream(CoreChannel.BufferPool); base.WritePreambleAndVersion(outputStream); base.WriteUInt16(2, outputStream); base.WriteUInt16(0, outputStream); base.WriteInt32((int) contentStream.Length, outputStream); base.WriteHeaders(headers, outputStream); outputStream.WriteTo(base.NetStream); outputStream.Close(); StreamHelper.CopyStream(contentStream, base.NetStream); contentStream.Close(); } }
public void SendErrorResponse(string e, bool bCloseConnection) { if (!this._bOneWayRequest) { ChunkedMemoryStream outputStream = new ChunkedMemoryStream(CoreChannel.BufferPool); base.WritePreambleAndVersion(outputStream); base.WriteUInt16(2, outputStream); base.WriteUInt16(0, outputStream); base.WriteInt32(0, outputStream); base.WriteUInt16(2, outputStream); base.WriteByte(3, outputStream); base.WriteUInt16(1, outputStream); base.WriteUInt16(3, outputStream); base.WriteByte(1, outputStream); base.WriteCountedString(e, outputStream); base.WriteUInt16(5, outputStream); base.WriteByte(0, outputStream); base.WriteUInt16(0, outputStream); outputStream.WriteTo(base.NetStream); outputStream.Close(); } }
protected override void SendErrorMessageIfPossible(Exception e) { if (!this._bOneWayRequest) { ChunkedMemoryStream outputStream = new ChunkedMemoryStream(CoreChannel.BufferPool); base.WritePreambleAndVersion(outputStream); base.WriteUInt16(2, outputStream); base.WriteUInt16(0, outputStream); base.WriteInt32(0, outputStream); base.WriteUInt16(2, outputStream); base.WriteByte(3, outputStream); base.WriteUInt16(1, outputStream); base.WriteUInt16(3, outputStream); base.WriteByte(1, outputStream); base.WriteCountedString(e.ToString(), outputStream); base.WriteUInt16(5, outputStream); base.WriteByte(0, outputStream); base.WriteUInt16(0, outputStream); outputStream.WriteTo(base.NetStream); outputStream.Close(); } }