示例#1
0
        protected void InitializeContext()
        {
            _thisHandle = GCHandle.Alloc(this);

            Method = GetVerb();

            RawTarget = GetRawUrl();
            // TODO version is slow.
            HttpVersion = GetVersion();
            Scheme      = SslStatus != SslStatus.Insecure ? Constants.HttpsScheme : Constants.HttpScheme;
            KnownMethod = VerbId;
            StatusCode  = 200;

            var originalPath = GetOriginalPath();

            if (KnownMethod == HttpApiTypes.HTTP_VERB.HttpVerbOPTIONS && string.Equals(RawTarget, "*", StringComparison.Ordinal))
            {
                PathBase = string.Empty;
                Path     = string.Empty;
            }
            else
            {
                // Path and pathbase are unescaped by RequestUriBuilder
                // The UsePathBase middleware will modify the pathbase and path correctly
                PathBase = string.Empty;
                Path     = originalPath;
            }

            var cookedUrl = GetCookedUrl();

            QueryString = cookedUrl.GetQueryString() ?? string.Empty;

            RequestHeaders      = new RequestHeaders(this);
            HttpResponseHeaders = new HeaderCollection();
            ResponseHeaders     = HttpResponseHeaders;

            if (_options.ForwardWindowsAuthentication)
            {
                WindowsUser = GetWindowsPrincipal();
                if (_options.AutomaticAuthentication)
                {
                    User = WindowsUser;
                }
            }

            ResetFeatureCollection();

            if (!_server.IsWebSocketAvailable(_pInProcessHandler))
            {
                _currentIHttpUpgradeFeature = null;
            }

            _streams = new Streams(this);

            (RequestBody, ResponseBody) = _streams.Start();

            var pipe = new Pipe(
                new PipeOptions(
                    _memoryPool,
                    readerScheduler: PipeScheduler.ThreadPool,
                    pauseWriterThreshold: PauseWriterThreshold,
                    resumeWriterThreshold: ResumeWriterTheshold,
                    minimumSegmentSize: MinAllocBufferSize));

            _bodyOutput = new OutputProducer(pipe);

            NativeMethods.HttpSetManagedContext(_pInProcessHandler, (IntPtr)_thisHandle);
        }
示例#2
0
        protected void InitializeContext()
        {
            // create a memory barrier between initialize and disconnect to prevent a possible
            // NullRef with disconnect being called before these fields have been written
            // disconnect aquires this lock as well
            lock (_abortLock)
            {
                _thisHandle = GCHandle.Alloc(this);

                Method = GetVerb() ?? string.Empty;

                RawTarget = GetRawUrl() ?? string.Empty;
                // TODO version is slow.
                HttpVersion = GetVersion();
                Scheme      = SslStatus != SslStatus.Insecure ? Constants.HttpsScheme : Constants.HttpScheme;
                KnownMethod = VerbId;
                StatusCode  = 200;

                var originalPath = GetOriginalPath();

                if (KnownMethod == HttpApiTypes.HTTP_VERB.HttpVerbOPTIONS && string.Equals(RawTarget, "*", StringComparison.Ordinal))
                {
                    PathBase = string.Empty;
                    Path     = string.Empty;
                }
                else
                {
                    // Path and pathbase are unescaped by RequestUriBuilder
                    // The UsePathBase middleware will modify the pathbase and path correctly
                    PathBase = string.Empty;
                    Path     = originalPath ?? string.Empty;
                }

                var cookedUrl = GetCookedUrl();
                QueryString = cookedUrl.GetQueryString() ?? string.Empty;

                RequestHeaders      = new RequestHeaders(this);
                HttpResponseHeaders = new HeaderCollection();
                ResponseHeaders     = HttpResponseHeaders;
                // Request headers can be modified by the app, read these first.
                RequestCanHaveBody = CheckRequestCanHaveBody();

                if (_options.ForwardWindowsAuthentication)
                {
                    WindowsUser = GetWindowsPrincipal();
                    if (_options.AutomaticAuthentication)
                    {
                        User = WindowsUser;
                    }
                }

                MaxRequestBodySize = _options.MaxRequestBodySize;

                ResetFeatureCollection();

                if (!_server.IsWebSocketAvailable(_requestNativeHandle))
                {
                    _currentIHttpUpgradeFeature = null;
                }

                _streams = new Streams(this);

                (RequestBody, ResponseBody) = _streams.Start();

                var pipe = new Pipe(new PipeOptions(
                                        _memoryPool,
                                        // The readerScheduler schedules internal non-blocking logic, so there's no reason to dispatch.
                                        // The writerScheduler is PipeScheduler.ThreadPool by default which is correct because it
                                        // schedules app code when backpressure is relieved which may block.
                                        readerScheduler: PipeScheduler.Inline,
                                        pauseWriterThreshold: PauseWriterThreshold,
                                        resumeWriterThreshold: ResumeWriterTheshold,
                                        minimumSegmentSize: MinAllocBufferSize));
                _bodyOutput = new OutputProducer(pipe);
            }

            NativeMethods.HttpSetManagedContext(_requestNativeHandle, (IntPtr)_thisHandle);
        }