/// <summary>
        /// Timeouts the connection if there hasn't been an read activity on the request body stream or any
        /// write activity on the response body stream.
        /// </summary>
        /// <param name="builder">The IAppBuilder instance.</param>
        /// <param name="options">The connection timeout options.</param>
        /// <returns>The IAppBuilder instance.</returns>
        /// <exception cref="System.ArgumentNullException">builder</exception>
        public static IAppBuilder ConnectionTimeout(this IAppBuilder builder, ConnectionTimeoutOptions options)
        {
            builder.MustNotNull("builder");
            options.MustNotNull("options");

            builder
                .UseOwin()
                .ConnectionTimeout(options);

            return builder;
        }
Exemple #2
0
        /// <summary>
        /// Timeouts the connection if there hasn't been an read activity on the request body stream or any
        /// write activity on the response body stream.
        /// </summary>
        /// <param name="options">The connection timeout options.</param>
        /// <returns>An OWIN middleware delegate.</returns>
        /// <exception cref="System.ArgumentNullException">options</exception>
        public static MidFunc ConnectionTimeout(ConnectionTimeoutOptions options)
        {
            options.MustNotNull("options");

            return
                next =>
                env =>
                {
                    var context = new OwinContext(env);
                    Stream requestBodyStream = context.Request.Body ?? Stream.Null;
                    Stream responseBodyStream = context.Response.Body;

                    options.Tracer.AsVerbose("Configure timeouts.");
                    TimeSpan connectionTimeout = options.Timeout;
                    context.Request.Body = new TimeoutStream(requestBodyStream, connectionTimeout, options.Tracer);
                    context.Response.Body = new TimeoutStream(responseBodyStream, connectionTimeout, options.Tracer);

                    options.Tracer.AsVerbose("Request with configured timeout forwarded.");
                    return next(env);
                };
        }
Exemple #3
0
        /// <summary>
        /// Timeouts the connection if there hasn't been an read activity on the request body stream or any
        /// write activity on the response body stream.
        /// </summary>
        /// <param name="builder">The OWIN builder instance.</param>
        /// <param name="options">The connection timeout options.</param>
        /// <returns>The OWIN builder instance.</returns>
        /// <exception cref="System.ArgumentNullException">builder</exception>
        /// <exception cref="System.ArgumentNullException">options</exception>
        public static BuildFunc ConnectionTimeout(this BuildFunc builder, ConnectionTimeoutOptions options)
        {
            builder.MustNotNull("builder");
            options.MustNotNull("options");

            builder(_ => ConnectionTimeout(options));
            return builder;
        }