@@ -32,32 +32,46 @@ internal class DefaultClientIO : IClientIO
32
32
public const string StreamingPath = "stream" ;
33
33
public const HttpMethodKind StreamingHttpMethod = HttpMethodKind . Post ;
34
34
35
- internal DefaultClientIO ( HttpClient client , AuthenticationHeaderValue authHeader , LastSeen lastSeen , Uri endpoint , TimeSpan ? timeout , Version httpVersion , IReadOnlyDictionary < string , string > customHeaders )
35
+ public static Builder Builder ( )
36
36
{
37
- client . AssertNotNull ( nameof ( client ) ) ;
38
- authHeader . AssertNotNull ( nameof ( authHeader ) ) ;
39
- endpoint . AssertNotNull ( nameof ( endpoint ) ) ;
40
- lastSeen . AssertNotNull ( nameof ( lastSeen ) ) ;
41
-
42
- this . client = client ;
43
- this . authHeader = authHeader ;
44
- this . lastSeen = lastSeen ;
45
- this . endpoint = endpoint ;
46
- this . clientTimeout = timeout ;
47
- this . customHeaders = customHeaders ;
37
+ return new Builder ( ) ;
38
+ }
39
+
40
+ internal DefaultClientIO ( Builder builder )
41
+ {
42
+ if ( builder . AuthHeader == null )
43
+ {
44
+ builder . Secret . AssertNotNull ( nameof ( builder . Secret ) ) ;
45
+ }
46
+
47
+ builder . Endpoint . AssertNotNull ( nameof ( builder . Endpoint ) ) ;
48
+
49
+ this . client = builder . Client ?? CreateClient ( ) ;
50
+ this . authHeader = builder . AuthHeader ?? AuthHeader ( builder . Secret ) ;
51
+ this . lastSeen = builder . LastSeen ?? new LastSeen ( ) ;
52
+ this . endpoint = builder . Endpoint ;
53
+ this . clientTimeout = builder . Timeout ;
54
+ this . customHeaders = builder . CustomHeaders ;
55
+
48
56
#if NETSTANDARD2_1
49
- this . httpVersion = httpVersion == null ? new Version ( 2 , 0 ) : httpVersion ;
57
+ this . httpVersion = builder . HttpVersion == null ? new Version ( 2 , 0 ) : builder . HttpVersion ;
50
58
#else
51
- this . httpVersion = httpVersion == null ? new Version ( 1 , 1 ) : httpVersion ;
59
+ this . httpVersion = builder . HttpVersion == null ? new Version ( 1 , 1 ) : builder . HttpVersion ;
52
60
#endif
53
61
}
54
62
55
- public DefaultClientIO ( string secret , Uri endpoint , TimeSpan ? timeout = null , HttpClient httpClient = null , Version httpVersion = null , IReadOnlyDictionary < string , string > customHeaders = null )
56
- : this ( httpClient ?? CreateClient ( ) , AuthHeader ( secret ) , new LastSeen ( ) , endpoint , timeout , httpVersion , customHeaders )
57
- { }
58
-
59
- public IClientIO NewSessionClient ( string secret ) =>
60
- new DefaultClientIO ( client , AuthHeader ( secret ) , lastSeen , endpoint , clientTimeout , httpVersion , customHeaders ) ;
63
+ public IClientIO NewSessionClient ( string secret )
64
+ {
65
+ return Builder ( )
66
+ . SetClient ( client )
67
+ . SetAuthHeader ( AuthHeader ( secret ) )
68
+ . SetLastSeen ( lastSeen )
69
+ . SetEndpoint ( endpoint )
70
+ . SetTimeout ( clientTimeout )
71
+ . SetHttpVersion ( httpVersion )
72
+ . SetCustomHeaders ( customHeaders )
73
+ . Build ( ) ;
74
+ }
61
75
62
76
public Task < RequestResult > DoRequest ( HttpMethodKind method , string path , string data , IReadOnlyDictionary < string , string > query = null , TimeSpan ? queryTimeout = null ) =>
63
77
DoRequestAsync ( method , path , data , query , queryTimeout ) ;
0 commit comments