1- using Newtonsoft . Json ;
2- using Supabase . Core ;
3- using Supabase . Core . Extensions ;
4- using Supabase . Functions . Interfaces ;
5- using Supabase . Functions . Responses ;
6- using System ;
1+ using System ;
72using System . Collections . Generic ;
83using System . Net . Http ;
94using System . Runtime . CompilerServices ;
105using System . Text ;
116using System . Threading . Tasks ;
127using System . Web ;
8+ using Newtonsoft . Json ;
9+ using Supabase . Core ;
10+ using Supabase . Core . Extensions ;
1311using Supabase . Functions . Exceptions ;
12+ using Supabase . Functions . Interfaces ;
13+ using Supabase . Functions . Responses ;
1414
1515[ assembly: InternalsVisibleTo ( "FunctionsTests" ) ]
1616
@@ -24,7 +24,7 @@ public partial class Client : IFunctionsClient
2424
2525 /// <summary>
2626 /// Function that can be set to return dynamic headers.
27- ///
27+ ///
2828 /// Headers specified in the method parameters will ALWAYS take precedence over headers returned by this function.
2929 /// </summary>
3030 public Func < Dictionary < string , string > > ? GetHeaders { get ; set ; }
@@ -45,8 +45,11 @@ public Client(string baseUrl)
4545 /// <param name="token">Anon Key.</param>
4646 /// <param name="options">Options</param>
4747 /// <returns></returns>
48- public async Task < HttpContent > RawInvoke ( string functionName , string ? token = null ,
49- InvokeFunctionOptions ? options = null )
48+ public async Task < HttpContent > RawInvoke (
49+ string functionName ,
50+ string ? token = null ,
51+ InvokeFunctionOptions ? options = null
52+ )
5053 {
5154 var url = $ "{ _baseUrl } /{ functionName } ";
5255
@@ -60,8 +63,11 @@ public async Task<HttpContent> RawInvoke(string functionName, string? token = nu
6063 /// <param name="token">Anon Key.</param>
6164 /// <param name="options">Options</param>
6265 /// <returns></returns>
63- public async Task < string > Invoke ( string functionName , string ? token = null ,
64- InvokeFunctionOptions ? options = null )
66+ public async Task < string > Invoke (
67+ string functionName ,
68+ string ? token = null ,
69+ InvokeFunctionOptions ? options = null
70+ )
6571 {
6672 var url = $ "{ _baseUrl } /{ functionName } ";
6773 var response = await HandleRequest ( url , token , options ) ;
@@ -77,8 +83,12 @@ public async Task<string> Invoke(string functionName, string? token = null,
7783 /// <param name="token">Anon Key.</param>
7884 /// <param name="options">Options</param>
7985 /// <returns></returns>
80- public async Task < T ? > Invoke < T > ( string functionName , string ? token = null ,
81- InvokeFunctionOptions ? options = null ) where T : class
86+ public async Task < T ? > Invoke < T > (
87+ string functionName ,
88+ string ? token = null ,
89+ InvokeFunctionOptions ? options = null
90+ )
91+ where T : class
8292 {
8393 var url = $ "{ _baseUrl } /{ functionName } ";
8494 var response = await HandleRequest ( url , token , options ) ;
@@ -96,8 +106,11 @@ public async Task<string> Invoke(string functionName, string? token = null,
96106 /// <param name="options"></param>
97107 /// <returns></returns>
98108 /// <exception cref="FunctionsException"></exception>
99- private async Task < HttpResponseMessage > HandleRequest ( string url , string ? token = null ,
100- InvokeFunctionOptions ? options = null )
109+ private async Task < HttpResponseMessage > HandleRequest (
110+ string url ,
111+ string ? token = null ,
112+ InvokeFunctionOptions ? options = null
113+ )
101114 {
102115 options ??= new InvokeFunctionOptions ( ) ;
103116
@@ -118,21 +131,24 @@ private async Task<HttpResponseMessage> HandleRequest(string url, string? token
118131
119132 builder . Query = query . ToString ( ) ;
120133
121- using var requestMessage = new HttpRequestMessage ( HttpMethod . Post , builder . Uri ) ;
122- requestMessage . Content = new StringContent ( JsonConvert . SerializeObject ( options . Body ) , Encoding . UTF8 ,
123- "application/json" ) ;
134+ using var requestMessage = new HttpRequestMessage ( options . HttpMethod , builder . Uri ) ;
135+ requestMessage . Content = new StringContent (
136+ JsonConvert . SerializeObject ( options . Body ) ,
137+ Encoding . UTF8 ,
138+ "application/json"
139+ ) ;
124140
125141 foreach ( var kvp in options . Headers )
126142 {
127143 requestMessage . Headers . TryAddWithoutValidation ( kvp . Key , kvp . Value ) ;
128144 }
129-
145+
130146 if ( _httpClient . Timeout != options . HttpTimeout )
131147 {
132148 _httpClient = new HttpClient ( ) ;
133149 _httpClient . Timeout = options . HttpTimeout ;
134150 }
135-
151+
136152 var response = await _httpClient . SendAsync ( requestMessage ) ;
137153
138154 if ( response . IsSuccessStatusCode && ! response . Headers . Contains ( "x-relay-error" ) )
@@ -143,10 +159,11 @@ private async Task<HttpResponseMessage> HandleRequest(string url, string? token
143159 {
144160 Content = content ,
145161 Response = response ,
146- StatusCode = ( int ) response . StatusCode
162+ StatusCode = ( int ) response . StatusCode ,
147163 } ;
148164 exception . AddReason ( ) ;
149165 throw exception ;
150166 }
151167 }
152- }
168+ }
169+
0 commit comments