Esempio n. 1
0
        public async Task Invoke(IDictionary <string, object> environment)
        {
            await _next(environment);

            var response = new OwinResponse(environment);

            if (response.Body == Stream.Null)
            {
                return;
            }

            string connection = response.GetHeader("Connection");

            if (response.Protocol.Equals("HTTP/1.1", StringComparison.OrdinalIgnoreCase) &&
                String.Equals(connection, "Close", StringComparison.OrdinalIgnoreCase))
            {
                var ms = new MemoryStream();

                using (response.Body)
                {
                    await response.Body.CopyToAsync(ms).ConfigureAwait(continueOnCapturedContext: false);
                }
                ms.Seek(0, SeekOrigin.Begin);
                response.Body = ms;
            }
        }
Esempio n. 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);
        }
Esempio n. 3
0
        public async Task Invoke(IDictionary <string, object> environment)
        {
            await _next(environment);

            var response = new OwinResponse(environment);
            var encoding = response.GetHeader("Content-Encoding");

            if (String.Equals(encoding, "gzip", StringComparison.OrdinalIgnoreCase))
            {
                response.Body = new GZipStream(response.Body, CompressionMode.Decompress);
            }
        }
        private string BuildRedirectUrl(OwinResponse response)
        {
            string location = response.GetHeader("Location");

            Uri uri;

            if (Uri.TryCreate(location, UriKind.Relative, out uri))
            {
                // If location is relative, we need to build a full url
                var previousRequest = new OwinRequest(response.Dictionary);
                var uriBuilder      = new UriBuilder(previousRequest.Uri);
                uriBuilder.Path = location;

                return(uriBuilder.ToString());
            }

            return(location);
        }
Esempio n. 5
0
        public async Task Invoke(IDictionary <string, object> environment)
        {
            await _next(environment);

            var response = new OwinResponse(environment);

            if (response.Body == Stream.Null)
            {
                return;
            }

            var transferEncoding = response.GetHeader("Transfer-Encoding");

            if (String.Equals(transferEncoding,
                              "chunked",
                              StringComparison.OrdinalIgnoreCase))
            {
                response.Body = new ChunkedStream(response.Body);
            }
        }
        public async Task Invoke(IDictionary <string, object> environment)
        {
            await _next(environment);

            var response = new OwinResponse(environment);

            if (response.Body == Stream.Null)
            {
                return;
            }

            string contentLengthRaw = response.GetHeader("Content-Length");
            long   contentLength;

            if (contentLengthRaw != null &&
                Int64.TryParse(contentLengthRaw, out contentLength))
            {
                response.Body = new ContentLengthStream(response.Body, contentLength);
            }
        }