internal unsafe HttpListenerRequest(System.Net.HttpListenerContext httpContext, RequestContextBase memoryBlob)
 {
     if (Logging.On)
     {
         Logging.PrintInfo(Logging.HttpListener, this, ".ctor", "httpContext#" + ValidationHelper.HashString(httpContext) + " memoryBlob# " + ValidationHelper.HashString((IntPtr)memoryBlob.RequestBlob));
     }
     if (Logging.On)
     {
         Logging.Associate(Logging.HttpListener, this, httpContext);
     }
     this.m_HttpContext  = httpContext;
     this.m_MemoryBlob   = memoryBlob;
     this.m_BoundaryType = BoundaryType.None;
     this.m_RequestId    = memoryBlob.RequestBlob.RequestId;
     this.m_ConnectionId = memoryBlob.RequestBlob.ConnectionId;
     this.m_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))
     {
         this.m_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))
     {
         this.m_CookedUrlHost = Marshal.PtrToStringUni((IntPtr)cookedUrl.pHost, cookedUrl.HostLength / 2);
     }
     if ((cookedUrl.pAbsPath != null) && (cookedUrl.AbsPathLength > 0))
     {
         this.m_CookedUrlPath = Marshal.PtrToStringUni((IntPtr)cookedUrl.pAbsPath, cookedUrl.AbsPathLength / 2);
     }
     if ((cookedUrl.pQueryString != null) && (cookedUrl.QueryStringLength > 0))
     {
         this.m_CookedUrlQuery = Marshal.PtrToStringUni((IntPtr)cookedUrl.pQueryString, cookedUrl.QueryStringLength / 2);
     }
     this.m_Version         = new Version(memoryBlob.RequestBlob.Version.MajorVersion, memoryBlob.RequestBlob.Version.MinorVersion);
     this.m_ClientCertState = ListenerClientCertState.NotInitialized;
     this.m_KeepAlive       = TriState.Unspecified;
     if (Logging.On)
     {
         Logging.PrintInfo(Logging.HttpListener, this, ".ctor", "httpContext#" + ValidationHelper.HashString(httpContext) + " RequestUri:" + ValidationHelper.ToString(this.RequestUri) + " Content-Length:" + ValidationHelper.ToString(this.ContentLength64) + " HTTP Method:" + ValidationHelper.ToString(this.HttpMethod));
     }
     if (Logging.On)
     {
         StringBuilder builder = new StringBuilder("HttpListenerRequest Headers:\n");
         for (int i = 0; i < this.Headers.Count; i++)
         {
             builder.Append("\t");
             builder.Append(this.Headers.GetKey(i));
             builder.Append(" : ");
             builder.Append(this.Headers.Get(i));
             builder.Append("\n");
         }
         Logging.PrintInfo(Logging.HttpListener, this, ".ctor", builder.ToString());
     }
 }
Пример #2
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
        }