Beispiel #1
0
        public static IAppBuilder KWebApi(this IAppBuilder builder, HttpConfiguration configuration, string pathPrefix = "api", string serviceNameSuffix = "", string namespacePrefix = "", bool outputCamelCase = false)
        {
            if (builder == null)
            {
                throw new ArgumentNullException("builder");
            }

            if (configuration == null)
            {
                throw new ArgumentNullException("configuration");
            }

            configuration.KWebApi(pathPrefix, serviceNameSuffix, namespacePrefix, outputCamelCase);

            HttpServer server = new HttpServer(configuration);

            try
            {
                HttpMessageHandlerOptions options = CreateOptions(builder, server, configuration);
                return(UseMessageHandler(builder, options));
            }
            catch
            {
                server.Dispose();
                throw;
            }
        }
        private static IAppBuilder UseMessageHandler(this IAppBuilder builder, HttpMessageHandlerOptions options)
        {
            Contract.Assert(builder != null);
            Contract.Assert(options != null);

            return(builder.Use(typeof(HttpMessageHandlerAdapter), options));
        }
        public static IAppBuilder UseWebApi(this IAppBuilder builder, HttpConfiguration configuration)
        {
            if (builder == null)
            {
                throw new ArgumentNullException("builder");
            }

            if (configuration == null)
            {
                throw new ArgumentNullException("configuration");
            }

            HttpServer server = new HttpServer(configuration);

            try
            {
                HttpMessageHandlerOptions options = CreateOptions(server, configuration);
                return(UseMessageHandler(builder, options));
            }
            catch
            {
                server.Dispose();
                throw;
            }
        }
        public static Func <IDictionary <string, object>, Task> CreateWebApiAppFunc(HttpConfiguration config)
        {
            var app     = new HttpServer(config);
            var options = new HttpMessageHandlerOptions()
            {
                MessageHandler       = app,
                BufferPolicySelector = new OwinBufferPolicySelector(),
                ExceptionLogger      = new WebApiExceptionLogger(),
                ExceptionHandler     = new WebApiExceptionHandler()
            };
            var handler = new HttpMessageHandlerAdapter(null, options);

            return((env) => handler.Invoke(new OwinContext(env)));
        }
        /// <summary>Adds a component to the OWIN pipeline for running a Web API endpoint.</summary>
        /// <param name="builder">The application builder.</param>
        /// <param name="httpServer">The http server.</param>
        /// <returns>The application builder.</returns>
        public static IAppBuilder UseWebApi(this IAppBuilder builder, HttpServer httpServer)
        {
            if (builder == null)
            {
                throw new ArgumentNullException("builder");
            }

            if (httpServer == null)
            {
                throw new ArgumentNullException("httpServer");
            }

            HttpConfiguration configuration = httpServer.Configuration;

            Contract.Assert(configuration != null);

            HttpMessageHandlerOptions options = CreateOptions(httpServer, configuration);

            return(UseMessageHandler(builder, options));
        }
Beispiel #6
0
        public static Func <IDictionary <string, object>, Task> CreateWebApiAppFunc2(HttpConfiguration config, HttpMessageHandlerOptions options = null)
        {
            var bufferPolicy = new OwinBufferPolicySelector();

            config.Services.Replace(typeof(IHostBufferPolicySelector), bufferPolicy); // Done just so App can get access to it.
            var app = new HttpServer(config);

            if (options == null)
            {
                options = new HttpMessageHandlerOptions()
                {
                    MessageHandler       = app,
                    BufferPolicySelector = bufferPolicy,
                    ExceptionLogger      = new GlobalErrorLoggingService(),
                    ExceptionHandler     = new GlobalErrorHandlerService()
                };
            }
            var handler = new HttpMessageHandlerAdapter(new NotFoundMiddleware(), options);

            return((env) => handler.Invoke(new OwinContext(env)));
        }
 public void HttpMessageHandlerOptions_DoesNotMatch(HttpMessageHandlerOptions options, ConfiguredHttpMessageHandler configuredHandler) =>
 Assert.Throws <InvalidOperationException>(() => options.CheckItMatches(configuredHandler));
 public void HttpMessageHandlerOptions_Matches(HttpMessageHandlerOptions options, ConfiguredHttpMessageHandler configuredHandler) =>
 Assert.Same(configuredHandler, options.CheckItMatches(configuredHandler));
 public void HttpMessageHandlerOptions_Instances(HttpMessageHandlerOptions options, bool expectedRedirects, bool expectedDecompression)
 {
     Assert.Equal(expectedRedirects, options.MayHandleRedirects);
     Assert.Equal(expectedDecompression, options.MayPerformDecompression);
 }