internal HttpListenerResponse(HttpListenerContext context)
 {
     _context = context;
       _keepAlive = true;
       _statusCode = 200;
       _statusDescription = "OK";
       _version = HttpVersion.Version11;
 }
 internal HttpRequestEventArgs(HttpListenerContext context)
 {
     _request = context.Request;
       _response = context.Response;
 }
 internal HttpListenerRequest(HttpListenerContext context)
 {
     _context = context;
       _contentLength = -1;
       _headers = new WebHeaderCollection ();
       _identifier = Guid.NewGuid ();
 }
        internal void Complete(HttpListenerContext context, bool syncCompleted)
        {
            var lsnr = context.Listener;
              if (!lsnr.Authenticate (context)) {
            lsnr.BeginGetContext (this);
            return;
              }

              _context = context;
              _syncCompleted = syncCompleted;

              lock (_sync)
            complete (this);
        }
 internal void Complete(HttpListenerContext context)
 {
     Complete (context, false);
 }
        private void cleanupContextRegistry()
        {
            lock (_ctxRegistrySync) {
            if (_ctxRegistry.Count == 0)
              return;

            // Need to copy this since closing will call the UnregisterContext method.
            var keys = _ctxRegistry.Keys;
            var ctxs = new HttpListenerContext[keys.Count];
            keys.CopyTo (ctxs, 0);
            _ctxRegistry.Clear ();
            for (var i = ctxs.Length - 1; i >= 0; i--)
              ctxs[i].Connection.Close (true);
              }
        }
        internal void UnregisterContext(HttpListenerContext context)
        {
            lock (_ctxRegistrySync)
            _ctxRegistry.Remove (context);

              lock (_ctxQueueSync) {
            var idx = _ctxQueue.IndexOf (context);
            if (idx >= 0)
              _ctxQueue.RemoveAt (idx);
              }
        }
 internal AuthenticationSchemes SelectAuthenticationScheme(HttpListenerContext context)
 {
     return AuthenticationSchemeSelector != null
      ? AuthenticationSchemeSelector (context.Request)
      : _authSchemes;
 }
        internal void RegisterContext(HttpListenerContext context)
        {
            lock (_ctxRegistrySync)
            _ctxRegistry[context] = context;

              HttpListenerAsyncResult ares = null;
              lock (_waitQueueSync) {
            if (_waitQueue.Count == 0) {
              lock (_ctxQueueSync)
            _ctxQueue.Add (context);
            }
            else {
              ares = _waitQueue[0];
              _waitQueue.RemoveAt (0);
            }
              }

              if (ares != null)
            ares.Complete (context);
        }
        internal bool Authenticate(HttpListenerContext context)
        {
            var schm = SelectAuthenticationScheme (context);
              if (schm == AuthenticationSchemes.Anonymous)
            return true;

              if (schm != AuthenticationSchemes.Basic && schm != AuthenticationSchemes.Digest) {
            context.Response.Close (HttpStatusCode.Forbidden);
            return false;
              }

              var realm = Realm;
              var req = context.Request;
              var user = HttpUtility.CreateUser (
            req.Headers["Authorization"], schm, realm, req.HttpMethod, UserCredentialsFinder);

              if (user != null && user.Identity.IsAuthenticated) {
            context.User = user;
            return true;
              }

              if (schm == AuthenticationSchemes.Basic)
            context.Response.CloseWithAuthChallenge (
              AuthenticationChallenge.CreateBasicChallenge (realm).ToBasicString ());

              if (schm == AuthenticationSchemes.Digest)
            context.Response.CloseWithAuthChallenge (
              AuthenticationChallenge.CreateDigestChallenge (realm).ToDigestString ());

              return false;
        }