@@ -5,11 +5,71 @@ namespace k8s;
5
5
6
6
public abstract partial class AbstractKubernetes
7
7
{
8
+ private static class HttpMethods
9
+ {
10
+ public static readonly HttpMethod Delete = HttpMethod . Delete ;
11
+ public static readonly HttpMethod Get = HttpMethod . Get ;
12
+ public static readonly HttpMethod Head = HttpMethod . Head ;
13
+ public static readonly HttpMethod Options = HttpMethod . Options ;
14
+ public static readonly HttpMethod Post = HttpMethod . Post ;
15
+ public static readonly HttpMethod Put = HttpMethod . Put ;
16
+ public static readonly HttpMethod Trace = HttpMethod . Trace ;
17
+ public static readonly HttpMethod Patch = new HttpMethod ( "Patch" ) ;
18
+ }
19
+
20
+ private sealed class QueryBuilder
21
+ {
22
+ private List < string > parameters = new List < string > ( ) ;
23
+
24
+ public void Append ( string key , params object [ ] values )
25
+ {
26
+ foreach ( var value in values )
27
+ {
28
+ switch ( value )
29
+ {
30
+ case int intval :
31
+ parameters . Add ( $ "{ key } ={ intval } ") ;
32
+ break ;
33
+ case string strval :
34
+ parameters . Add ( $ "{ key } ={ Uri . EscapeDataString ( strval ) } ") ;
35
+ break ;
36
+ case bool boolval :
37
+ parameters . Add ( $ "{ key } ={ ( boolval ? "true" : "false" ) } ") ;
38
+ break ;
39
+ default :
40
+ // null
41
+ break ;
42
+ }
43
+ }
44
+ }
45
+
46
+ public override string ToString ( )
47
+ {
48
+ if ( parameters . Count > 0 )
49
+ {
50
+ return $ "?{ string . Join ( "&" , parameters ) } ";
51
+ }
8
52
53
+ return "" ;
54
+ }
55
+ }
56
+
57
+ private Task < HttpResponseMessage > SendRequest < T > ( T body , HttpRequestMessage httpRequest , CancellationToken cancellationToken )
58
+ {
59
+ if ( body != null )
60
+ {
61
+ var requestContent = KubernetesJson . Serialize ( body ) ;
62
+ httpRequest . Content = new StringContent ( requestContent , System . Text . Encoding . UTF8 ) ;
63
+ httpRequest . Content . Headers . ContentType = GetHeader ( body ) ;
64
+ return SendRequestRaw ( requestContent , httpRequest , cancellationToken ) ;
65
+ }
66
+
67
+ return SendRequestRaw ( "" , httpRequest , cancellationToken ) ;
68
+ }
9
69
10
70
public virtual TimeSpan HttpClientTimeout { get ; set ; } = TimeSpan . FromSeconds ( 100 ) ;
11
71
12
- protected internal virtual MediaTypeHeaderValue GetHeader ( object body )
72
+ protected virtual MediaTypeHeaderValue GetHeader ( object body )
13
73
{
14
74
if ( body == null )
15
75
{
@@ -46,9 +106,9 @@ private MediaTypeHeaderValue GetHeader(V1Patch body)
46
106
}
47
107
}
48
108
49
- protected internal abstract Task < HttpOperationResponse < T > > CreateResultAsync < T > ( HttpRequestMessage httpRequest , HttpResponseMessage httpResponse , bool ? watch , CancellationToken cancellationToken ) ;
109
+ protected abstract Task < HttpOperationResponse < T > > CreateResultAsync < T > ( HttpRequestMessage httpRequest , HttpResponseMessage httpResponse , bool ? watch , CancellationToken cancellationToken ) ;
50
110
51
- protected internal abstract HttpRequestMessage CreateRequest ( string relativeUri , HttpMethod method , IReadOnlyDictionary < string , IReadOnlyList < string > > customHeaders ) ;
111
+ protected abstract HttpRequestMessage CreateRequest ( string relativeUri , HttpMethod method , IReadOnlyDictionary < string , IReadOnlyList < string > > customHeaders ) ;
52
112
53
- protected internal abstract Task < HttpResponseMessage > SendRequestRaw ( string requestContent , HttpRequestMessage httpRequest , CancellationToken cancellationToken ) ;
113
+ protected abstract Task < HttpResponseMessage > SendRequestRaw ( string requestContent , HttpRequestMessage httpRequest , CancellationToken cancellationToken ) ;
54
114
}
0 commit comments