Esempio n. 1
0
        /// <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));
        }