NetWrok.HTTP.Request.WriteToStream C# (CSharp) Method

WriteToStream() private method

private WriteToStream ( Stream outputStream ) : void
outputStream Stream
return void
        void WriteToStream(Stream outputStream)
        {
            uploadProgress = 0f;
            var stream = new BinaryWriter (outputStream);
            bool hasBody = false;
            var pathComponent = proxy==null?uri.PathAndQuery:uri.AbsoluteUri;
            stream.Write (Protocol.enc.GetBytes (method.ToUpper () + " " + pathComponent + " " + protocol));
            stream.Write (Protocol.EOL);
            if (uri.UserInfo != null && uri.UserInfo != "") {
                if (!headers.Contains ("Authorization")) {
                    headers.Set ("Authorization", "Basic " + System.Convert.ToBase64String (Protocol.enc.GetBytes (uri.UserInfo)));
                }
            }
            if (!headers.Contains ("Accept")) {
                headers.Add("Accept", "*/*");
            }
            if (bytes != null && bytes.Length > 0) {
                headers.Set ("Content-Length", bytes.Length.ToString ());
                // Override any previous value
                hasBody = true;
            } else {
                headers.Pop ("Content-Length");
            }

            headers.Write (stream);

            stream.Write (Protocol.EOL);

            if (hasBody) {
                var totalBytes = bytes.Length;
                var reader = new MemoryStream(bytes);
                var index = 0;
                var a = new byte[1024];
                while(index < totalBytes) {
                    var readCount = reader.Read (a, 0, 1024);
                    stream.Write(a, 0, readCount);
                    uploadProgress += (totalBytes / (float)readCount);
                    index += readCount;
                }
                //stream.Write (bytes);
            }

            uploadProgress = 1f;
        }