Esempio n. 1
0
        /// <summary>
        /// Asynchronously writes the envelope for the inner HTTP message.
        /// </summary>
        /// <param name="responseMessage">The response message to write the envelope.</param>
        /// <returns>A task that represents the asynchronous write operation.</returns>
        private async Task WriteInnerEnvelopeAsync(ODataAsynchronousResponseMessage responseMessage)
        {
            // Write response line.
            string statusMessage = HttpUtils.GetStatusMessage(responseMessage.StatusCode);

            await this.rawOutputContext.TextWriter.WriteLineAsync(
                string.Concat(ODataConstants.HttpVersionInAsync, " ", responseMessage.StatusCode, " ", statusMessage))
            .ConfigureAwait(false);

            // Write headers.
            if (responseMessage.Headers != null)
            {
                foreach (var headerPair in responseMessage.Headers)
                {
                    await this.rawOutputContext.TextWriter.WriteLineAsync(string.Concat(headerPair.Key, ": ", headerPair.Value))
                    .ConfigureAwait(false);
                }
            }

            // Write CRLF.
            await this.rawOutputContext.TextWriter.WriteLineAsync()
            .ConfigureAwait(false);

            // Flush the writer since we won't be able to access it anymore.
            await this.rawOutputContext.TextWriter.FlushAsync()
            .ConfigureAwait(false);
        }
        /// <summary>
        /// Writes the envelope for the inner HTTP message.
        /// </summary>
        /// <param name="responseMessage">The response message to write the envelope.</param>
        private void WriteInnerEnvelope(ODataAsynchronousResponseMessage responseMessage)
        {
            // Write response line.
            string statusMessage = HttpUtils.GetStatusMessage(responseMessage.StatusCode);

            this.rawOutputContext.TextWriter.WriteLine("{0} {1} {2}", ODataConstants.HttpVersionInAsync, responseMessage.StatusCode, statusMessage);

            // Write headers.
            if (responseMessage.Headers != null)
            {
                foreach (var headerPair in responseMessage.Headers)
                {
                    string headerName  = headerPair.Key;
                    string headerValue = headerPair.Value;
                    this.rawOutputContext.TextWriter.WriteLine(string.Format(CultureInfo.InvariantCulture, "{0}: {1}", headerName, headerValue));
                }
            }

            // Write CRLF.
            this.rawOutputContext.TextWriter.WriteLine();

            // Flush the writer since we won't be able to access it anymore.
            this.rawOutputContext.TextWriter.Flush();
        }