当前位置: 首页>>代码示例>>C#>>正文


C# IDictionary.GetOwinValue方法代码示例

本文整理汇总了C#中IDictionary.GetOwinValue方法的典型用法代码示例。如果您正苦于以下问题:C# IDictionary.GetOwinValue方法的具体用法?C# IDictionary.GetOwinValue怎么用?C# IDictionary.GetOwinValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IDictionary的用法示例。


在下文中一共展示了IDictionary.GetOwinValue方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Invoke

        public async Task Invoke(IDictionary<string, object> environment)
        {
            if (environment == null)
            {
                throw new ArgumentNullException("environment");
            }

            Stream requestBody = environment.GetOwinValue<Stream>(OwinConstants.RequestBodyKey);
            HttpRequestMessage request = CreateRequestMessage(environment, requestBody);
            if (!requestBody.CanSeek && _bufferPolicySelector.UseBufferedInputStream(hostContext: environment))
            {
                await BufferRequestBodyAsync(environment, request.Content);
            }
            CancellationToken cancellationToken = environment.GetOwinValue<CancellationToken>(OwinConstants.CallCancelledKey);

            SetPrincipal(environment);

            HttpResponseMessage response = null;
            bool callNext = false;
            try
            {
                response = await _messageInvoker.SendAsync(request, cancellationToken);

                // Handle null responses
                if (response == null)
                {
                    throw Error.InvalidOperation(SRResources.SendAsync_ReturnedNull);
                }

                // Handle soft 404s where no route matched - call the next component
                if (IsSoftNotFound(request, response))
                {
                    callNext = true;
                }
                else
                {
                    if (response.Content != null && _bufferPolicySelector.UseBufferedOutputStream(response))
                    {
                        response = await BufferResponseBodyAsync(request, response);
                    }

                    await SendResponseMessageAsync(environment, response);
                }
            }
            finally
            {
                // Note that the HttpRequestMessage is explicitly NOT disposed.  Disposing it would close the input stream
                // and prevent cascaded components from accessing it.  The server MUST handle any necessary cleanup upon
                // request completion.
                request.DisposeRequestResources();
                if (response != null)
                {
                    response.Dispose();
                }
            }

            // Call the next component if no route matched
            if (callNext)
            {
                await _next.Invoke(environment);
            }
        }
开发者ID:brianly,项目名称:aspnetwebstack,代码行数:62,代码来源:HttpMessageHandlerAdapter.cs

示例2: SendResponseMessageAsync

        private static Task SendResponseMessageAsync(IDictionary<string, object> environment, HttpResponseMessage response)
        {
            environment[OwinConstants.ResponseStatusCodeKey] = response.StatusCode;
            environment[OwinConstants.ResponseReasonPhraseKey] = response.ReasonPhrase;

            // Copy non-content headers
            IDictionary<string, string[]> responseHeaders = environment.GetOwinValue<IDictionary<string, string[]>>(OwinConstants.ResponseHeadersKey);
            foreach (KeyValuePair<string, IEnumerable<string>> header in response.Headers)
            {
                responseHeaders[header.Key] = header.Value.ToArray();
            }

            if (response.Content == null)
            {
                return TaskHelpers.Completed();
            }
            else
            {
                // Trigger delayed content-length calculations before enumerating the headers.
                response.Content.Headers.ContentLength = response.Content.Headers.ContentLength;

                // Copy content headers
                foreach (KeyValuePair<string, IEnumerable<string>> contentHeader in response.Content.Headers)
                {
                    responseHeaders[contentHeader.Key] = contentHeader.Value.ToArray();
                }

                // Copy body
                Stream responseBody = environment.GetOwinValue<Stream>(OwinConstants.ResponseBodyKey);
                return response.Content.CopyToAsync(responseBody);
            }
        }
开发者ID:brianly,项目名称:aspnetwebstack,代码行数:32,代码来源:HttpMessageHandlerAdapter.cs

示例3: CreateRequestMessage

        private static HttpRequestMessage CreateRequestMessage(IDictionary<string, object> environment, Stream requestBody)
        {
            string requestMethod = environment.GetOwinValue<string>(OwinConstants.RequestMethodKey);
            IDictionary<string, string[]> requestHeaders = environment.GetOwinValue<IDictionary<string, string[]>>(OwinConstants.RequestHeadersKey);
            string requestPathBase;
            Uri requestUri = CreateRequestUri(environment, requestHeaders, out requestPathBase);

            // Create the request
            HttpRequestMessage request = new HttpRequestMessage(new HttpMethod(requestMethod), requestUri);

            // Set the body
            HttpContent content = new StreamContent(requestBody);
            request.Content = content;

            // Copy the headers
            foreach (KeyValuePair<string, string[]> header in requestHeaders)
            {
                if (!request.Headers.TryAddWithoutValidation(header.Key, header.Value))
                {
                    bool success = request.Content.Headers.TryAddWithoutValidation(header.Key, header.Value);
                    Contract.Assert(success, "Every header can be added either to the request headers or to the content headers");
                }
            }

            // Map the OWIN environment keys to the request properties keys that Web API expects
            MapRequestProperties(request, environment, requestPathBase);

            return request;
        }
开发者ID:brianly,项目名称:aspnetwebstack,代码行数:29,代码来源:HttpMessageHandlerAdapter.cs

示例4: CreateRequestUri

        // Implements the algorithm for reconstructing a URI according to section 5.4 of the OWIN specification
        private static Uri CreateRequestUri(IDictionary<string, object> environment, IDictionary<string, string[]> requestHeaders, out string requestPathBase)
        {
            StringBuilder uriBuilder = new StringBuilder();

            // Append request scheme
            string requestScheme = environment.GetOwinValue<string>(OwinConstants.RequestSchemeKey);
            uriBuilder.Append(requestScheme);

            uriBuilder.Append("://");

            // Append host and port
            string[] hostHeaderValues;
            if (requestHeaders.TryGetValue("Host", out hostHeaderValues) && hostHeaderValues.Length > 0)
            {
                uriBuilder.Append(hostHeaderValues[0]);
            }
            else
            {
                throw Error.InvalidOperation(SRResources.CreateRequestURI_MissingHostHeader);
            }

            // Append request path
            requestPathBase = environment.GetOwinValue<string>(OwinConstants.RequestPathBaseKey);
            uriBuilder.Append(requestPathBase);
            string requestPath = environment.GetOwinValue<string>(OwinConstants.RequestPathKey);
            uriBuilder.Append(requestPath);

            // Append query string
            string requestQueryString = environment.GetOwinValue<string>(OwinConstants.RequestQueryStringKey);
            if (requestQueryString.Length > 0)
            {
                uriBuilder.Append('?');
                uriBuilder.Append(requestQueryString);
            }

            return new Uri(uriBuilder.ToString(), UriKind.Absolute);
        }
开发者ID:brianly,项目名称:aspnetwebstack,代码行数:38,代码来源:HttpMessageHandlerAdapter.cs

示例5: SendResponseMessageAsync

        private static Task SendResponseMessageAsync(IDictionary<string, object> environment, HttpResponseMessage response)
        {
            environment[OwinConstants.ResponseStatusCodeKey] = response.StatusCode;
            environment[OwinConstants.ResponseReasonPhraseKey] = response.ReasonPhrase;

            // Copy non-content headers
            IDictionary<string, string[]> responseHeaders = environment.GetOwinValue<IDictionary<string, string[]>>(OwinConstants.ResponseHeadersKey);
            foreach (KeyValuePair<string, IEnumerable<string>> header in response.Headers)
            {
                responseHeaders[header.Key] = header.Value.ToArray();
            }

            HttpContent responseContent = response.Content;
            if (responseContent == null)
            {
                // Set the content-length to 0 to prevent the server from sending back the response chunked
                responseHeaders["Content-Length"] = new string[] { "0" };
                return TaskHelpers.Completed();
            }
            else
            {
                // Copy content headers
                foreach (KeyValuePair<string, IEnumerable<string>> contentHeader in responseContent.Headers)
                {
                    responseHeaders[contentHeader.Key] = contentHeader.Value.ToArray();
                }

                // Copy body
                Stream responseBody = environment.GetOwinValue<Stream>(OwinConstants.ResponseBodyKey);
                return responseContent.CopyToAsync(responseBody);
            }
        }
开发者ID:samgithub-duplicate,项目名称:aspnetwebstack,代码行数:32,代码来源:HttpMessageHandlerAdapter.cs


注:本文中的IDictionary.GetOwinValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。