private async Task SendContinue(CancellationToken cancellationToken)
        {
            if (!ContinueOnRead)
            {
                return;
            }
            if (StringComparer.OrdinalIgnoreCase.Compare(Environment.GetRequestHeader("Expect", ""), "100-continue") == 0)
            {
                var response_protocol = Environment.Get(OwinEnvironment.Owin.ResponseProtocol, Environment.Get(OwinEnvironment.Owin.RequestProtocol, "HTTP/1.0"));
                if (response_protocol != "HTTP/1.0")
                {
                    var status_code   = 100;
                    var reason_phrase = HttpReasonPhrase.GetReasonPhrase(100);
                    using (var writer = new StreamWriter(BaseStream, System.Text.Encoding.ASCII, 2048, true)) {
                        writer.NewLine = "\r\n";
                        await writer.WriteAsync(response_protocol).ConfigureAwait(false);

                        await writer.WriteAsync(' ').ConfigureAwait(false);

                        await writer.WriteAsync(status_code.ToString()).ConfigureAwait(false);

                        await writer.WriteAsync(' ').ConfigureAwait(false);

                        await writer.WriteLineAsync(reason_phrase).ConfigureAwait(false);

                        await writer.WriteLineAsync().ConfigureAwait(false);
                    }
                }
            }
            ContinueOnRead = false;
        }
Beispiel #2
0
        private async Task SendResponseHeaderAsync(CancellationToken cancellationToken)
        {
            Context.OnSendingHeaders.Invoke();
            var response_protocol = Environment.Get(OwinEnvironment.Owin.ResponseProtocol, Environment.Get(OwinEnvironment.Owin.RequestProtocol, "HTTP/1.0"));
            var status_code       = Environment.Get(OwinEnvironment.Owin.ResponseStatusCode, 200);
            var reason_phrase     = Environment.Get(OwinEnvironment.Owin.ResponseReasonPhrase, HttpReasonPhrase.GetReasonPhrase(status_code));

            Environment.SetResponseHeaderOptional("Date", () => DateTimeOffset.Now.ToString("R"));
            using (var writer = new StreamWriter(BaseStream, System.Text.Encoding.ASCII, 2048, true)) {
                writer.NewLine = "\r\n";
                await writer.WriteAsync(response_protocol).ConfigureAwait(false);

                await writer.WriteAsync(' ').ConfigureAwait(false);

                await writer.WriteAsync(status_code.ToString()).ConfigureAwait(false);

                await writer.WriteAsync(' ').ConfigureAwait(false);

                await writer.WriteLineAsync(reason_phrase).ConfigureAwait(false);

                if (Environment.TryGetValue <IDictionary <string, string[]> >(OwinEnvironment.Owin.ResponseHeaders, out var headers))
                {
                    foreach (var ent in headers)
                    {
                        await writer.WriteAsync(ent.Key).ConfigureAwait(false);

                        await writer.WriteAsync(':').ConfigureAwait(false);

                        if (ent.Value.Length > 0)
                        {
                            await writer.WriteAsync(ent.Value[0]);

                            for (var i = 1; i < ent.Value.Length; i++)
                            {
                                await writer.WriteAsync(',').ConfigureAwait(false);

                                await writer.WriteAsync(ent.Value[i]).ConfigureAwait(false);
                            }
                        }
                        await writer.WriteLineAsync().ConfigureAwait(false);
                    }
                }
                await writer.WriteLineAsync().ConfigureAwait(false);
            }
            Submitted = true;
        }