Esempio n. 1
0
        public JsonRequestContent(Object val, HttpJsonSerializer serializer)
        {
            Guard.ArgumentNotNull(val, nameof(val));
            Guard.ArgumentNotNull(serializer, nameof(serializer));

            this._value      = val;
            this._serializer = serializer;
        }
Esempio n. 2
0
        public RestClient(RestClientConfiguration configuration, Version requestedApiVersion = null)
        {
            Configuration        = configuration;
            _requestedApiVersion = requestedApiVersion;
            JsonSerializer       = new HttpJsonSerializer();

            ManagedHandler handler;
            var            uri = Configuration.EndpointBaseUri;

            switch (uri.Scheme.ToLowerInvariant())
            {
            case "http":
                var builder = new UriBuilder(uri)
                {
                    Scheme = configuration.Credentials.IsTlsCredentials() ? "https" : "http"
                };
                uri     = builder.Uri;
                handler = new ManagedHandler();
                break;

            case "https":
                handler = new ManagedHandler();
                break;

            case "unix":
                var pipeString = uri.LocalPath;
                handler = new ManagedHandler(async(string host, int port, CancellationToken cancellationToken) =>
                {
                    var sock = new Socket(AddressFamily.Unix, SocketType.Stream, ProtocolType.Unspecified);
                    await sock.ConnectAsync(new UnixDomainSocketEndPoint(pipeString));
                    return(sock);
                });
                uri = new UriBuilder("http", uri.Segments.Last()).Uri;
                break;

            default:
                throw new Exception($"Unsupported url scheme '{configuration.EndpointBaseUri.Scheme}'");
            }

            this.EndpointBaseUri = uri;

            _client         = new HttpClient(Configuration.Credentials.GetHandler(handler), true);
            _client.Timeout = InfiniteTimeout;
            _client.Timeout = Configuration.Timeout;
        }