@@ -3373,6 +3373,30 @@ def test_set_heading_if_not_set_multiple_headers_with_mixed_states(self):
33733373 # Original headers should still exist
33743374 self .assertEqual (result ["headers" ]["X-Another-Header" ], "another-value" )
33753375
3376+ def test_set_heading_if_not_set_two_defaults_two_customs_one_override (self ):
3377+ """Test setting two default headers when two custom headers exist, with one custom overriding one default"""
3378+ # Start with two custom headers
3379+ options = {
3380+ "headers" : {
3381+ "X-Request-ID" : "my-custom-request-id" , # This should override the default
3382+ "X-Tenant-ID" : "tenant-123" , # This is custom-only
3383+ }
3384+ }
3385+
3386+ # Try to set two default headers
3387+ result = set_heading_if_not_set (options , "X-SDK-Version" , "1.0.0" )
3388+ result = set_heading_if_not_set (result , "X-Request-ID" , "default-uuid" )
3389+
3390+ # Verify all four headers exist with correct values
3391+ self .assertEqual (result ["headers" ]["X-SDK-Version" ], "1.0.0" ) # Default was set
3392+ self .assertEqual (
3393+ result ["headers" ]["X-Request-ID" ], "my-custom-request-id"
3394+ ) # Custom overrode default
3395+ self .assertEqual (
3396+ result ["headers" ]["X-Tenant-ID" ], "tenant-123"
3397+ ) # Custom preserved
3398+ self .assertEqual (len (result ["headers" ]), 3 ) # Exactly 3 headers
3399+
33763400 def test_set_heading_if_not_set_with_empty_string_value (self ):
33773401 """Test that empty string values in custom headers are preserved and not overridden."""
33783402 options = {"headers" : {"X-Custom-Header" : "" }}
@@ -3406,6 +3430,35 @@ def test_set_heading_if_not_set_case_sensitivity(self):
34063430 self .assertEqual (result ["headers" ]["X-Custom-Header" ], "uppercase" )
34073431 self .assertEqual (result ["headers" ]["x-custom-header" ], "lowercase" )
34083432
3433+ @patch .object (rest .RESTClientObject , "request" )
3434+ def test_content_type_cannot_be_overridden_by_custom_headers (self , mock_request ):
3435+ """Test that Content-Type header cannot be overridden by custom headers."""
3436+ response_body = '{"allowed": true, "resolution": "1234"}'
3437+ mock_request .return_value = mock_response (response_body , 200 )
3438+
3439+ body = ClientCheckRequest (
3440+ object = "document:2021-budget" ,
3441+ relation = "reader" ,
3442+ user = "user:81684243-9356-4421-8fbf-a4f8d36aa31b" ,
3443+ )
3444+
3445+ configuration = self .configuration
3446+ configuration .store_id = store_id
3447+ configuration .authorization_model_id = "01GXSA8YR785C4FYS3C0RTG7B1"
3448+
3449+ with OpenFgaClient (configuration ) as api_client :
3450+ # Try to override Content-Type with a custom value
3451+ custom_options = {"headers" : {"Content-Type" : "text/plain" }}
3452+ api_client .check (body = body , options = custom_options )
3453+
3454+ call_args = mock_request .call_args
3455+ headers = call_args [1 ]["headers" ]
3456+
3457+ # Content-Type should be application/json, NOT the custom text/plain
3458+ self .assertEqual (headers .get ("Content-Type" ), "application/json" )
3459+ self .assertNotEqual (headers .get ("Content-Type" ), "text/plain" )
3460+ api_client .close ()
3461+
34093462 @patch .object (rest .RESTClientObject , "request" )
34103463 def test_check_with_custom_headers_override_defaults (self , mock_request ):
34113464 """Test that custom headers in options override default headers for check API."""
0 commit comments