示例#1
0
        internal HttpContextBuilder(ApplicationWrapper application, bool allowSynchronousIO, bool preserveExecutionContext)
        {
            _application              = application ?? throw new ArgumentNullException(nameof(application));
            AllowSynchronousIO        = allowSynchronousIO;
            _preserveExecutionContext = preserveExecutionContext;
            _httpContext              = new DefaultHttpContext();
            _responseFeature          = new ResponseFeature(Abort);
            _requestLifetimeFeature   = new RequestLifetimeFeature(Abort);

            var request = _httpContext.Request;

            request.Protocol = HttpProtocol.Http11;
            request.Method   = HttpMethods.Get;

            _requestPipe = new Pipe();

            var responsePipe = new Pipe();

            _responseReaderStream       = new ResponseBodyReaderStream(responsePipe, ClientInitiatedAbort, () => _responseReadCompleteCallback?.Invoke(_httpContext));
            _responsePipeWriter         = new ResponseBodyPipeWriter(responsePipe, ReturnResponseMessageAsync);
            _responseFeature.Body       = new ResponseBodyWriterStream(_responsePipeWriter, () => AllowSynchronousIO);
            _responseFeature.BodyWriter = _responsePipeWriter;

            _httpContext.Features.Set <IHttpBodyControlFeature>(this);
            _httpContext.Features.Set <IHttpResponseFeature>(_responseFeature);
            _httpContext.Features.Set <IHttpResponseBodyFeature>(_responseFeature);
            _httpContext.Features.Set <IHttpRequestLifetimeFeature>(_requestLifetimeFeature);
            _httpContext.Features.Set <IHttpResponseTrailersFeature>(_responseTrailersFeature);
        }
示例#2
0
        /// <summary>
        /// Create a new handler.
        /// </summary>
        /// <param name="pathBase">The base path.</param>
        /// <param name="application">The <see cref="IHttpApplication{TContext}"/>.</param>
        internal ClientHandler(PathString pathBase, ApplicationWrapper application)
        {
            _application = application ?? throw new ArgumentNullException(nameof(application));

            // PathString.StartsWithSegments that we use below requires the base path to not end in a slash.
            if (pathBase.HasValue && pathBase.Value.EndsWith('/'))
            {
                pathBase = new PathString(pathBase.Value[..^1]); // All but the last character
示例#3
0
        /// <summary>
        /// Create a new handler.
        /// </summary>
        /// <param name="pathBase">The base path.</param>
        /// <param name="application">The <see cref="IHttpApplication{TContext}"/>.</param>
        internal ClientHandler(PathString pathBase, ApplicationWrapper application)
        {
            _application = application ?? throw new ArgumentNullException(nameof(application));

            // PathString.StartsWithSegments that we use below requires the base path to not end in a slash.
            if (pathBase.HasValue && pathBase.Value.EndsWith("/"))
            {
                pathBase = new PathString(pathBase.Value.Substring(0, pathBase.Value.Length - 1));
            }
            _pathBase = pathBase;
        }
示例#4
0
        internal HttpContextBuilder(ApplicationWrapper application, bool allowSynchronousIO, bool preserveExecutionContext)
        {
            _application              = application ?? throw new ArgumentNullException(nameof(application));
            AllowSynchronousIO        = allowSynchronousIO;
            _preserveExecutionContext = preserveExecutionContext;
            _httpContext              = new DefaultHttpContext();
            _responseFeature          = new ResponseFeature(Abort);

            var request = _httpContext.Request;

            request.Protocol = "HTTP/1.1";
            request.Method   = HttpMethods.Get;

            _httpContext.Features.Set <IHttpBodyControlFeature>(this);
            _httpContext.Features.Set <IHttpResponseFeature>(_responseFeature);
            _httpContext.Features.Set <IHttpResponseStartFeature>(_responseFeature);
            _httpContext.Features.Set <IHttpRequestLifetimeFeature>(_requestLifetimeFeature);
            _httpContext.Features.Set <IHttpResponseTrailersFeature>(_responseTrailersFeature);

            _responseStream       = new ResponseStream(ReturnResponseMessageAsync, AbortRequest, () => AllowSynchronousIO, () => _responseReadCompleteCallback?.Invoke(_httpContext));
            _responseFeature.Body = _responseStream;
        }