Beispiel #1
0
        internal static bool LegacyShouldIncludeErrorDetail(this HttpRequestMessage request)
        {
            HttpConfiguration        configuration            = request.GetConfiguration();
            IncludeErrorDetailPolicy includeErrorDetailPolicy = IncludeErrorDetailPolicy.Default;

            if (configuration != null)
            {
                includeErrorDetailPolicy = configuration.IncludeErrorDetailPolicy;
            }
            switch (includeErrorDetailPolicy)
            {
            case IncludeErrorDetailPolicy.Default:
                Lazy <bool> includeErrorDetail = request.GetProperty <Lazy <bool> >(HttpPropertyKeys.IncludeErrorDetailKey);
                if (includeErrorDetail != null)
                {
                    // If we are on webhost and the user hasn't changed the IncludeErrorDetailPolicy
                    // look up into the Request's property bag else default to LocalOnly.
                    return(includeErrorDetail.Value);
                }

                goto case IncludeErrorDetailPolicy.LocalOnly;

            case IncludeErrorDetailPolicy.LocalOnly:
                return(request.IsLocal());

            case IncludeErrorDetailPolicy.Always:
                return(true);

            case IncludeErrorDetailPolicy.Never:
            default:
                return(false);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Gets a value indicating whether the request originates from a batch.
        /// </summary>
        /// <param name="request">The HTTP request.</param>
        /// <returns><see langword="true"/> if the request originates from a batch; otherwise, <see langword="false"/>.</returns>
        public static bool IsBatchRequest(this HttpRequestMessage request)
        {
            if (request == null)
            {
                throw Error.ArgumentNull("request");
            }

            return(request.GetProperty <bool>(HttpPropertyKeys.IsBatchRequest));
        }
        /// <summary>
        /// Gets the <see cref="System.Web.Http.Routing.IHttpRouteData"/> for the given request or null if not available.
        /// </summary>
        /// <param name="request">The HTTP request.</param>
        /// <returns>The <see cref="System.Web.Http.Routing.IHttpRouteData"/> or null.</returns>
        public static IHttpRouteData GetRouteData(this HttpRequestMessage request)
        {
            if (request == null)
            {
                throw Error.ArgumentNull("request");
            }

            return(request.GetProperty <IHttpRouteData>(HttpPropertyKeys.HttpRouteDataKey));
        }
Beispiel #4
0
        /// <summary>
        /// Gets the <see cref="System.Web.Http.Controllers.HttpActionDescriptor"/> selected for the given request or null if not available.
        /// </summary>
        /// <param name="request">The HTTP request.</param>
        /// <returns>The <see cref="System.Web.Http.Controllers.HttpActionDescriptor"/> or null.</returns>
        public static HttpActionDescriptor GetActionDescriptor(this HttpRequestMessage request)
        {
            if (request == null)
            {
                throw Error.ArgumentNull("request");
            }

            return(request.GetProperty <HttpActionDescriptor>(HttpPropertyKeys.HttpActionDescriptorKey));
        }
Beispiel #5
0
        /// <summary>
        /// Gets the <see cref="System.Threading.SynchronizationContext"/> for the given request or null if not available.
        /// </summary>
        /// <param name="request">The HTTP request.</param>
        /// <returns>The <see cref="System.Threading.SynchronizationContext"/> or null.</returns>
        public static SynchronizationContext GetSynchronizationContext(this HttpRequestMessage request)
        {
            if (request == null)
            {
                throw Error.ArgumentNull("request");
            }

            return(request.GetProperty <SynchronizationContext>(HttpPropertyKeys.SynchronizationContextKey));
        }
        /// <summary>
        /// Gets the current <see cref="T:System.ServiceModel.Security.SecurityMessageProperty"/>
        /// stored in <see cref="M:HttpRequestMessage.Properties"/> for the given request.
        /// </summary>
        /// <param name="request">The HTTP request.</param>
        /// <returns>The <see cref="SecurityMessageProperty"/>.</returns>
        public static SecurityMessageProperty GetSecurityMessageProperty(this HttpRequestMessage request)
        {
            if (request == null)
            {
                throw Error.ArgumentNull("request");
            }

            return(request.GetProperty <SecurityMessageProperty>(SecurityKey));
        }
        /// <summary>
        /// Gets the <see cref="HttpConfiguration"/> for the given request.
        /// </summary>
        /// <param name="request">The HTTP request.</param>
        /// <returns>The <see cref="HttpConfiguration"/>.</returns>
        public static HttpConfiguration GetConfiguration(this HttpRequestMessage request)
        {
            if (request == null)
            {
                throw Error.ArgumentNull("request");
            }

            return(request.GetProperty <HttpConfiguration>(HttpPropertyKeys.HttpConfigurationKey));
        }
        /// <summary>
        /// Retrieves the root virtual path associated with this request.
        /// </summary>
        /// <param name="request">The <see cref="HttpRequestMessage"/>.</param>
        /// <returns>The root virtual path associated with this request.</returns>
        public static string GetVirtualPathRoot(this HttpRequestMessage request)
        {
            if (request == null)
            {
                throw Error.ArgumentNull("request");
            }

            return(request.GetProperty <string>(HttpPropertyKeys.VirtualPathRoot));
        }
Beispiel #9
0
        /// <summary>
        /// Gets the response message of the <see cref="HttpResponseException"/> thrown by a custom route implementation.
        /// </summary>
        /// <remarks>Custom <see cref="IHttpRoute"/> implementations can throw <see cref="HttpResponseException"/> to indicate that the incoming request matches
        /// the route but is a bad request (HTTP 400 status code).</remarks>
        /// <param name="request">The incoming request message.</param>
        public static HttpResponseMessage GetRoutingErrorResponse(this HttpRequestMessage request)
        {
            if (request == null)
            {
                throw Error.ArgumentNull("request");
            }

            return(request.GetProperty <HttpResponseMessage>(HttpPropertyKeys.RoutingErrorResponseKey));
        }
Beispiel #10
0
        private static HttpContext GetHttpContext(HttpRequestMessage request)
        {
            var context = request.GetProperty <HttpContext>(nameof(HttpContext));

            if (context == null)
            {
                throw new InvalidOperationException("Http Request message must have a HttpContext.");
            }

            return(context);
        }
        /// <summary>
        /// Gets a value indicating whether the request originates from a local address or not.
        /// </summary>
        /// <param name="request">The HTTP request.</param>
        /// <returns><see langword="true"/> if the request originates from a local address; otherwise, <see langword="false"/>.</returns>
        public static bool IsLocal(this HttpRequestMessage request)
        {
            if (request == null)
            {
                throw Error.ArgumentNull("request");
            }

            Lazy <bool> isLocal = request.GetProperty <Lazy <bool> >(HttpPropertyKeys.IsLocalKey);

            return(isLocal == null ? false : isLocal.Value);
        }
        private static HttpContext GetHttpContext(HttpRequestMessage request)
        {
            var context = request.GetProperty <HttpContext>(nameof(HttpContext));

            if (context == null)
            {
                var message = ShimResources.FormatHttpRequestMessage_MustHaveHttpContext(
                    nameof(HttpRequestMessage),
                    "HttpRequestMessageHttpContextExtensions.GetHttpRequestMessage");
                throw new InvalidOperationException(message);
            }

            return(context);
        }
Beispiel #13
0
        internal static bool LegacyIsLocal(this HttpRequestMessage request)
        {
            Lazy <bool> isLocal = request.GetProperty <Lazy <bool> >(HttpPropertyKeys.IsLocalKey);

            return(isLocal == null ? false : isLocal.Value);
        }
Beispiel #14
0
 internal static HttpConfiguration LegacyGetConfiguration(this HttpRequestMessage request)
 {
     return(request.GetProperty <HttpConfiguration>(HttpPropertyKeys.HttpConfigurationKey));
 }
Beispiel #15
0
 internal static IHttpRouteData LegacyGetRouteData(this HttpRequestMessage request)
 {
     return(request.GetProperty <IHttpRouteData>(HttpPropertyKeys.HttpRouteDataKey));
 }