Пример #1
0
        internal RequestState(IHttpRequestFeature requestFeature, IHttpContextFactory factory,
                              IFeatureCollection featureCollection)
        {
            _factory = factory;
            _requestAbortedSource = new CancellationTokenSource();
            _pipelineFinished     = false;

            var contextFeatures = new FeatureCollection(featureCollection);

            contextFeatures.Set(requestFeature);
            _responseFeature = new ResponseFeature {
                Protocol = requestFeature.Protocol
            };
            contextFeatures.Set <IHttpResponseFeature>(_responseFeature);
            var requestLifetimeFeature = new HttpRequestLifetimeFeature();

            contextFeatures.Set <IHttpRequestLifetimeFeature>(requestLifetimeFeature);

            _responseStream                       = new WriteOnlyResponseStream(AbortRequest);
            _responseFeature.Body                 = _responseStream;
            _responseFeature.StatusCode           = 200;
            requestLifetimeFeature.RequestAborted = _requestAbortedSource.Token;

            Context = _factory.Create(contextFeatures);
        }
Пример #2
0
        internal RequestState(IHttpRequestFeature requestFeature, IHttpContextFactory factory,
                              IFeatureCollection featureCollection)
        {
            _factory = factory;
            _requestAbortedSource = new CancellationTokenSource();
            _pipelineFinished     = false;

            var contextFeatures = new FeatureCollection(featureCollection);

            contextFeatures.Set(requestFeature);

            _responseStream  = new WriteOnlyResponseStream(AbortRequest);
            _responseFeature = new ResponseFeature(requestFeature.Protocol, 200, null, _responseStream, new HeaderDictionary())
            {
                Abort = Abort
            };
            contextFeatures.Set <IHttpResponseFeature>(_responseFeature);
            contextFeatures.Set <IHttpResponseBodyFeature>(new StreamResponseBodyFeature(_responseStream));
            var requestLifetimeFeature = new HttpRequestLifetimeFeature();

            contextFeatures.Set <IHttpRequestLifetimeFeature>(requestLifetimeFeature);
            requestLifetimeFeature.RequestAborted = _requestAbortedSource.Token;

            Context = _factory.Create(contextFeatures);
        }