private bool IsRequestForHttp2Upgrade(OwinRequest request)
        {
            // TODO: Supported methods?  None called out in the 01 spec, but the sample uses GET.
            // POST would be problematic as you'd also have to consume all of the request data before completing the upgrade.

            // Headers
            // Connection: Upgrade
            // Upgrade: HTTP/2.0
            return string.Equals(request.GetHeader("Connection"), "Upgrade", StringComparison.OrdinalIgnoreCase)
                && string.Equals(request.GetHeader("Upgrade"), "HTTP/2.0", StringComparison.OrdinalIgnoreCase);
        }
Exemple #2
0
        public Task Invoke(IDictionary<string, object> env)
        {
            var request = new OwinRequest(env);

            var logger = _kernel.Get<ILogger>();

            var requestHeaders = new StringBuilder();
            foreach (var header in request.Headers)
            {
                requestHeaders.AppendLine(header.Key + " = " + request.GetHeader(header.Key));
            }

            Task task = _next(env);

            var response = new OwinResponse(env);

            var responseHeaders = new StringBuilder();
            foreach (var header in response.Headers)
            {
                responseHeaders.AppendLine(header.Key + " = " + response.GetHeader(header.Key));
            }

            logger.Log("URI: " + request.Uri + " " + Environment.NewLine +
                       "Request Headers: \r\n " + requestHeaders.ToString() + Environment.NewLine +
                       "Response Headers: \r\n " + responseHeaders.ToString());

            return task;
        }
        public Task Invoke(IDictionary<string, object> environment)
        {
            OwinRequest request = new OwinRequest(environment);
            OwinResponse response = new OwinResponse(environment);

            response.ContentType = "text/plain";

            string responseText = request.GetHeader("breadcrumbs") + "\r\n"
                + "PathBase: " + request.PathBase + "\r\n"
                + "Path: " + request.Path + "\r\n";

            return response.WriteAsync(responseText);
        }
        public async Task Invoke(IDictionary<string, object> environment)
        {
            var request = new OwinRequest(environment);
            Uri uri = request.Uri;

            // Create a stream for the host and port so we can send the request
            Stream stream = await _streamFactory.CreateStream(uri).ConfigureAwait(continueOnCapturedContext: false);

            var requestWriter = new StreamWriter(stream);

            // Request line
            requestWriter.WriteLine("{0} {1} {2}", request.Method, uri.LocalPath, request.Protocol);

            // Write headers
            foreach (var header in request.Headers)
            {
                requestWriter.WriteLine("{0}: {1}", header.Key, request.GetHeader(header.Key));
            }

            // End headers
            requestWriter.WriteLine();

            if (request.Body == null)
            {
                // End request
                requestWriter.WriteLine();
            }

            // Flush buffered content to the stream async
            await requestWriter.FlushAsync().ConfigureAwait(continueOnCapturedContext: false);

            if (request.Body != null)
            {
                // Copy the body to the request
                await request.Body.CopyToAsync(stream).ConfigureAwait(continueOnCapturedContext: false);
            }

            var response = new OwinResponse(environment);

            // Parse the response
            HttpParser.ParseResponse(stream, (protocol, statusCode, reasonPhrase) =>
            {
                response.Protocol = protocol;
                response.StatusCode = statusCode;
                response.ReasonPhrase = reasonPhrase;
            },
            (key, value) => response.SetHeader(key, value));

            // Set the body to the rest of the stream
            response.Body = stream;
        }
Exemple #5
0
        public Task Invoke(IDictionary<string, object> env)
        {
            var request = new OwinRequest(env);

            // This header is set on app harbor since ssl is terminated at the load balancer
            var scheme = request.GetHeader("X-Forwarded-Proto");

            if (!String.IsNullOrEmpty(scheme))
            {
                env[OwinConstants.RequestScheme] = scheme;
            }

            return _next(env);
        }
 private bool IsIE(IDictionary<string, object> environment)
 {
     OwinRequest request = new OwinRequest(environment);
     return request.GetHeader("User-Agent").Contains("MSIE");
 }