public void Should_cache_handler_between_multiple_instances()
        {
            var handler1 = provider.Obtain(null);
            var handler2 = new SocketsHandlerProvider(settings).Obtain(null);

            handler2.Should().BeSameAs(handler1);
        }
        public void Should_cache_handler_by_equal_settings()
        {
            var universalTransportSettings = new UniversalTransportSettings();
            var settings1 = universalTransportSettings.ToSocketsTransportSettings();
            var settings2 = universalTransportSettings.ToSocketsTransportSettings();

            var handler1 = new SocketsHandlerProvider(settings1).Obtain(null);
            var handler2 = new SocketsHandlerProvider(settings2).Obtain(null);

            handler2.Should().BeSameAs(handler1);
        }
        public void Should_return_different_handlers_for_different_settings()
        {
            var settings2 = new SocketsTransportSettings {
                ConnectionLifetime = 5.Hours()
            };
            var provider2 = new SocketsHandlerProvider(settings2);

            var handler1 = provider.Obtain(null);
            var handler2 = provider2.Obtain(null);

            handler2.Should().NotBeSameAs(handler1);
        }
        public void Should_return_different_handlers_for_different_certificate_validation_callback()
        {
            var universalTransportSettings = new UniversalTransportSettings();
            var settings1 = universalTransportSettings.ToSocketsTransportSettings();
            var settings2 = universalTransportSettings.ToSocketsTransportSettings();

            settings1.RemoteCertificateValidationCallback = (sender, certificate, chain, errors) => true;
            var handler1 = new SocketsHandlerProvider(settings1).Obtain(null);
            var handler2 = new SocketsHandlerProvider(settings2).Obtain(null);

            handler2.Should().NotBeSameAs(handler1);
        }
Beispiel #5
0
        public SocketsTransport([NotNull] SocketsTransportSettings settings, [NotNull] ILog log)
        {
            this.settings = settings ?? throw new ArgumentNullException(nameof(settings));
            this.log      = log ?? throw new ArgumentNullException(nameof(log));

            handlerProvider = new SocketsHandlerProvider(settings);
            timeoutProvider = new TimeoutProvider(settings.RequestAbortTimeout, this.log);
            errorHandler    = new ErrorHandler(this.log);
            socketTuner     = new SocketTuner(settings, this.log);
            bodyReader      = new BodyReader(
                settings.BufferFactory,
                len => settings.UseResponseStreaming(len),
                () => settings.MaxResponseBodySize,
                this.log);
        }
 public void TestSetup()
 {
     settings = new SocketsTransportSettings();
     provider = new SocketsHandlerProvider(settings);
 }