Exemplo n.º 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);
        }