示例#1
0
 // Use this to save the blob from dispose if this object was never used (never given to a user) and is about to be
 // disposed.
 internal void DetachBlob(NativeRequestContext memoryBlob)
 {
     if (memoryBlob != null && (object)memoryBlob == (object)_nativeRequestContext)
     {
         _nativeRequestContext = null;
     }
 }
示例#2
0
 internal unsafe bool ValidateRequest(NativeRequestContext requestMemory)
 {
     // Block potential DOS attacks
     if (requestMemory.RequestBlob->Headers.UnknownHeaderCount > UnknownHeaderLimit)
     {
         SendError(requestMemory.RequestBlob->RequestId, HttpStatusCode.BadRequest, authChallenges: null);
         return(false);
     }
     return(true);
 }
示例#3
0
 internal RequestContext(WebListener server, NativeRequestContext memoryBlob)
 {
     // TODO: Verbose log
     _server     = server;
     _memoryBlob = memoryBlob;
     _request    = new Request(this, _memoryBlob);
     _response   = new Response(this);
     _request.ReleasePins();
     AuthenticationChallenges = server.AuthenticationManager.AuthenticationSchemes & ~AuthenticationSchemes.AllowAnonymous;
 }
示例#4
0
        internal unsafe bool ValidateAuth(NativeRequestContext requestMemory)
        {
            var requestV2 = (UnsafeNclNativeMethods.HttpApi.HTTP_REQUEST_V2 *)requestMemory.RequestBlob;

            if (!AuthenticationManager.AllowAnonymous && !AuthenticationManager.CheckAuthenticated(requestV2->pRequestInfo))
            {
                SendError(requestMemory.RequestBlob->RequestId, HttpStatusCode.Unauthorized,
                          AuthenticationManager.GenerateChallenges(AuthenticationManager.AuthenticationSchemes));
                return(false);
            }
            return(true);
        }
示例#5
0
        // should only be called from RequestContext
        internal void Dispose()
        {
            // TODO: Verbose log
            _isDisposed = true;
            NativeRequestContext memoryBlob = _nativeRequestContext;

            if (memoryBlob != null)
            {
                memoryBlob.Dispose();
                _nativeRequestContext = null;
            }
            if (_nativeStream != null)
            {
                _nativeStream.Dispose();
            }
        }
示例#6
0
        internal unsafe Request(RequestContext httpContext, NativeRequestContext memoryBlob)
        {
            // TODO: Verbose log
            _requestContext       = httpContext;
            _nativeRequestContext = memoryBlob;
            _contentBoundaryType  = BoundaryType.None;

            // Set up some of these now to avoid refcounting on memory blob later.
            _requestId    = memoryBlob.RequestBlob->RequestId;
            _connectionId = memoryBlob.RequestBlob->ConnectionId;
            _contextId    = memoryBlob.RequestBlob->UrlContext;
            _sslStatus    = memoryBlob.RequestBlob->pSslInfo == null ? SslStatus.Insecure :
                            memoryBlob.RequestBlob->pSslInfo->SslClientCertNegotiated == 0 ? SslStatus.NoClientCert :
                            SslStatus.ClientCert;
            if (memoryBlob.RequestBlob->pRawUrl != null && memoryBlob.RequestBlob->RawUrlLength > 0)
            {
                _rawUrl = Marshal.PtrToStringAnsi((IntPtr)memoryBlob.RequestBlob->pRawUrl, memoryBlob.RequestBlob->RawUrlLength);
            }

            UnsafeNclNativeMethods.HttpApi.HTTP_COOKED_URL cookedUrl = memoryBlob.RequestBlob->CookedUrl;
            if (cookedUrl.pHost != null && cookedUrl.HostLength > 0)
            {
                _cookedUrlHost = Marshal.PtrToStringUni((IntPtr)cookedUrl.pHost, cookedUrl.HostLength / 2);
            }
            if (cookedUrl.pAbsPath != null && cookedUrl.AbsPathLength > 0)
            {
                _cookedUrlPath = Marshal.PtrToStringUni((IntPtr)cookedUrl.pAbsPath, cookedUrl.AbsPathLength / 2);
            }
            if (cookedUrl.pQueryString != null && cookedUrl.QueryStringLength > 0)
            {
                _cookedUrlQuery = Marshal.PtrToStringUni((IntPtr)cookedUrl.pQueryString, cookedUrl.QueryStringLength / 2);
            }

            UrlPrefix prefix       = httpContext.Server.UrlPrefixes.GetPrefix((int)_contextId);
            string    originalPath = RequestPath;

            // These paths are both unescaped already.
            if (originalPath.Length == prefix.Path.Length - 1)
            {
                // They matched exactly except for the trailing slash.
                _pathBase = originalPath;
                _path     = string.Empty;
            }
            else
            {
                // url: /base/path, prefix: /base/, base: /base, path: /path
                // url: /, prefix: /, base: , path: /
                _pathBase = originalPath.Substring(0, prefix.Path.Length - 1);
                _path     = originalPath.Substring(prefix.Path.Length - 1);
            }

            int major = memoryBlob.RequestBlob->Version.MajorVersion;
            int minor = memoryBlob.RequestBlob->Version.MinorVersion;

            if (major == 1 && minor == 1)
            {
                _httpVersion = Constants.V1_1;
            }
            else if (major == 1 && minor == 0)
            {
                _httpVersion = Constants.V1_0;
            }
            else
            {
                _httpVersion = new Version(major, minor);
            }

            _httpMethod = UnsafeNclNativeMethods.HttpApi.GetVerb(RequestBuffer, OriginalBlobAddress);
            _headers    = new HeaderCollection(new RequestHeaders(_nativeRequestContext));

            var requestV2 = (UnsafeNclNativeMethods.HttpApi.HTTP_REQUEST_V2 *)memoryBlob.RequestBlob;

            _user = AuthenticationManager.GetUser(requestV2->pRequestInfo, requestV2->RequestInfoCount);

            GetTlsTokenBindingInfo();

            // TODO: Verbose log parameters
        }
示例#7
0
 internal RequestHeaders(NativeRequestContext requestMemoryBlob)
 {
     _requestMemoryBlob = requestMemoryBlob;
 }
示例#8
0
 internal AsyncAcceptContext(WebListener server)
 {
     _server = server;
     _tcs    = new TaskCompletionSource <RequestContext>();
     _nativeRequestContext = new NativeRequestContext(this);
 }