@@ -87,6 +87,40 @@ void main() {
8787 );
8888 });
8989
90+ test ('set header on rpc' , () async {
91+ final httpClient = CustomHttpClient ();
92+ final postgrest = PostgrestClient (rootUrl, httpClient: httpClient);
93+
94+ await postgrest
95+ .rpc ('empty-succ' )
96+ .setHeader ("myKey" , "myValue" )
97+ .select ()
98+ .head ();
99+ expect (httpClient.lastRequest! .headers, containsPair ("myKey" , "myValue" ));
100+
101+ // Other following requests should not have the header
102+ await postgrest.rpc ('empty-succ' ).select ().head ();
103+ expect (httpClient.lastRequest! .headers,
104+ isNot (containsPair ("myKey" , "myValue" )));
105+ });
106+
107+ test ('set header on query builder' , () async {
108+ final httpClient = CustomHttpClient ();
109+ final postgrest = PostgrestClient (rootUrl, httpClient: httpClient);
110+
111+ await postgrest
112+ .from ('empty-succ' )
113+ .setHeader ("myKey" , "myValue" )
114+ .select ()
115+ .head ();
116+ expect (httpClient.lastRequest! .headers, containsPair ("myKey" , "myValue" ));
117+
118+ // Other following requests should not have the header
119+ await postgrest.from ('empty-succ' ).select ().head ();
120+ expect (httpClient.lastRequest! .headers,
121+ isNot (containsPair ("myKey" , "myValue" )));
122+ });
123+
90124 test ('switch schema' , () async {
91125 final postgrest = PostgrestClient (rootUrl, schema: 'personal' );
92126 final res = await postgrest.from ('users' ).select ();
0 commit comments