File tree Expand file tree Collapse file tree 3 files changed +46
-2
lines changed Expand file tree Collapse file tree 3 files changed +46
-2
lines changed Original file line number Diff line number Diff line change @@ -64,7 +64,10 @@ def __init__(
6464 self .supabase_url = supabase_url
6565 self .supabase_key = supabase_key
6666 self .options = copy .copy (options )
67- self .options .headers = copy .copy (self ._get_auth_headers ())
67+ self .options .headers = {
68+ ** options .headers ,
69+ ** self ._get_auth_headers (),
70+ }
6871
6972 self .rest_url = f"{ supabase_url } /rest/v1"
7073 self .realtime_url = f"{ supabase_url } /realtime/v1" .replace ("http" , "ws" )
Original file line number Diff line number Diff line change @@ -63,7 +63,10 @@ def __init__(
6363 self .supabase_url = supabase_url
6464 self .supabase_key = supabase_key
6565 self .options = copy .copy (options )
66- self .options .headers = copy .copy (self ._get_auth_headers ())
66+ self .options .headers = {
67+ ** options .headers ,
68+ ** self ._get_auth_headers (),
69+ }
6770
6871 self .rest_url = f"{ supabase_url } /rest/v1"
6972 self .realtime_url = f"{ supabase_url } /realtime/v1" .replace ("http" , "ws" )
Original file line number Diff line number Diff line change @@ -132,3 +132,41 @@ def test_global_authorization_header_issue():
132132 client = create_client (url , key , options )
133133
134134 assert client .options .headers .get ("apiKey" ) == key
135+
136+
137+ def test_custom_headers ():
138+ url = os .environ .get ("SUPABASE_TEST_URL" )
139+ key = os .environ .get ("SUPABASE_TEST_KEY" )
140+
141+ options = ClientOptions (
142+ headers = {
143+ "x-app-name" : "apple" ,
144+ "x-version" : "1.0" ,
145+ }
146+ )
147+
148+ client = create_client (url , key , options )
149+
150+ assert client .options .headers .get ("x-app-name" ) == "apple"
151+ assert client .options .headers .get ("x-version" ) == "1.0"
152+
153+
154+ def test_custom_headers_immutable ():
155+ url = os .environ .get ("SUPABASE_TEST_URL" )
156+ key = os .environ .get ("SUPABASE_TEST_KEY" )
157+
158+ options = ClientOptions (
159+ headers = {
160+ "x-app-name" : "apple" ,
161+ "x-version" : "1.0" ,
162+ }
163+ )
164+
165+ client1 = create_client (url , key , options )
166+ client2 = create_client (url , key , options )
167+
168+ client1 .options .headers ["x-app-name" ] = "grapes"
169+
170+ assert client1 .options .headers .get ("x-app-name" ) == "grapes"
171+ assert client1 .options .headers .get ("x-version" ) == "1.0"
172+ assert client2 .options .headers .get ("x-app-name" ) == "apple"
You can’t perform that action at this time.
0 commit comments