/// <summary> /// Issue a request to a server, and return the (IDisposable) response. /// </summary> /// <exception cref="ShiftIt.Http.TimeoutException">Timeouts while reading or writing sockets.</exception> /// <exception cref="System.Net.Sockets.SocketException">Low level transport exception occured.</exception> public IHttpResponse Request(IHttpRequest request, Action <long> sendProgress = null) { var socket = (request.Secure) ? _conn.ConnectSSL(request.Target, Timeout) : _conn.ConnectUnsecured(request.Target, Timeout); var Tx = new StreamWriter(socket); Tx.Write(request.RequestHead); Tx.Flush(); if (request.DataStream != null) { if (request.DataLength > 0) { StreamTools.CopyBytesToLength(request.DataStream, socket, request.DataLength, Timeout, sendProgress); } else { StreamTools.CopyBytesToTimeout(request.DataStream, socket, sendProgress); } } socket.Flush(); return(_parser.Parse(socket, Timeout)); }
public void should_be_able_to_read_entire_stream() { Assert.That(_subject.IsComplete(), Is.False); var ms = new MemoryStream(); StreamTools.CopyBytesToTimeout(_subject, ms, null); var result = Encoding.UTF8.GetString(ms.ToArray()); Assert.That(result, Is.EqualTo(expected)); Assert.That(_subject.IsComplete(), Is.True); }