Beispiel #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SimpleHttpServer"/> class.
        /// </summary>
        /// <param name="handler">The function that handles incoming proxied requests.</param>
        /// <param name="options">Configuration options for the server.</param>
        public SimpleHttpServer(
            Func<HttpListenerContext, Task<HttpResponseMessage>> handler,
            SimpleHttpServerOptions options = null)
        {
            options = options ?? SimpleHttpServerOptions.GetDefaultOptions();

            if (options.RequestHeaders == null)
            {
                throw new ArgumentNullException("options");
            }

            Port = options.Port == 0 ? GetEmptyPort() : options.Port;
            _requestHandler = handler;

            _listener = new HttpListener
            {
                AuthenticationSchemes = options.AuthenticationScheme,
                IgnoreWriteExceptions = true
            };

            _listener.Prefixes.Add(string.Format("http://localhost:{0}/", Port.ToString(CultureInfo.InvariantCulture)));

            _listener.Start();

            _listenerLoopCancellationTokenSource = new CancellationTokenSource();

            StartListenLoop(_listenerLoopCancellationTokenSource.Token);
        }
Beispiel #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="NtlmProxy"/> class.
 /// </summary>
 /// <param name="proxiedHostname">The proxied hostname.</param>
 /// <param name="serverOptions">Configuration options for the server.</param>
 public NtlmProxy(Uri proxiedHostname, SimpleHttpServerOptions serverOptions = null)
 {
     _options  = serverOptions ?? SimpleHttpServerOptions.GetDefaultOptions();
     _server   = new SimpleHttpServer(ProcessRequest, serverOptions);
     _hostname = proxiedHostname;
 }