internal ChunkedRequestStream (
   Stream stream, byte[] buffer, int offset, int count, HttpListenerContext context)
   : base (stream, buffer, offset, count)
 {
   _context = context;
   _decoder = new ChunkStream ((WebHeaderCollection) context.Request.Headers);
 }
 internal HttpListenerResponse (HttpListenerContext context)
 {
   _context = context;
   _headers = new WebHeaderCollection ();
   _keepAlive = true;
   _statusCode = 200;
   _statusDescription = "OK";
   _version = HttpVersion.Version11;
 }
    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);
 }
 internal HttpListenerRequest (HttpListenerContext context)
 {
   _context = context;
   _contentLength = -1;
   _headers = new WebHeaderCollection ();
   _identifier = Guid.NewGuid ();
 }
Example #6
0
    internal void UnregisterContext (HttpListenerContext context)
    {
      lock (_ctxRegistrySync)
        _ctxRegistry.Remove (context);

      lock (_ctxQueueSync) {
        var i = _ctxQueue.IndexOf (context);
        if (i >= 0)
          _ctxQueue.RemoveAt (i);
      }
    }
Example #7
0
 internal AuthenticationSchemes SelectAuthenticationScheme (HttpListenerContext context)
 {
   return AuthenticationSchemeSelector != null
          ? AuthenticationSchemeSelector (context.Request)
          : _authSchemes;
 }
Example #8
0
    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);
    }
Example #9
0
    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;
    }
Example #10
0
    private void cleanupContextRegistry ()
    {
      lock (_ctxRegistrySync) {
        if (_ctxRegistry.Count == 0)
          return;

        // Need to copy this since closing will call UnregisterContext.
        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 HttpRequestEventArgs (HttpListenerContext context)
 {
   _request = context.Request;
   _response = context.Response;
 }