File tree Expand file tree Collapse file tree 2 files changed +14
-11
lines changed
src/Providers/Http/Collections
tests/unit/Providers/Http/Collections Expand file tree Collapse file tree 2 files changed +14
-11
lines changed Original file line number Diff line number Diff line change @@ -115,15 +115,17 @@ private function set(string $name, $value): void
115
115
}
116
116
$ lowerName = strtolower ($ name );
117
117
118
- // If header exists with different casing, use the existing casing
118
+ // If header exists with different casing, remove the old casing
119
119
if (isset ($ this ->headersMap [$ lowerName ])) {
120
- $ actualName = $ this ->headersMap [$ lowerName ];
121
- $ this ->headers [$ actualName ] = $ normalizedValues ;
122
- } else {
123
- // New header, use provided casing
124
- $ this ->headers [$ name ] = $ normalizedValues ;
125
- $ this ->headersMap [$ lowerName ] = $ name ;
120
+ $ oldName = $ this ->headersMap [$ lowerName ];
121
+ if ($ oldName !== $ name ) {
122
+ unset($ this ->headers [$ oldName ]);
123
+ }
126
124
}
125
+
126
+ // Always use the new casing
127
+ $ this ->headers [$ name ] = $ normalizedValues ;
128
+ $ this ->headersMap [$ lowerName ] = $ name ;
127
129
}
128
130
129
131
/**
Original file line number Diff line number Diff line change @@ -83,15 +83,16 @@ public function testCaseInsensitiveReplacement(): void
83
83
{
84
84
$ headers = new HeadersCollection (['Content-Type ' => 'application/json ' ]);
85
85
86
- // withHeader with different casing should replace existing
86
+ // withHeader with different casing should replace existing with new casing
87
87
$ newHeaders = $ headers ->withHeader ('content-type ' , 'text/html ' );
88
88
89
89
$ this ->assertEquals (['text/html ' ], $ newHeaders ->get ('Content-Type ' ));
90
+ $ this ->assertEquals (['text/html ' ], $ newHeaders ->get ('content-type ' ));
90
91
91
- // Original casing should be preserved
92
+ // New casing should be used
92
93
$ all = $ newHeaders ->getAll ();
93
- $ this ->assertArrayHasKey ('Content-Type ' , $ all );
94
- $ this ->assertArrayNotHasKey ('content-type ' , $ all );
94
+ $ this ->assertArrayHasKey ('content-type ' , $ all );
95
+ $ this ->assertArrayNotHasKey ('Content-Type ' , $ all );
95
96
}
96
97
97
98
/**
You can’t perform that action at this time.
0 commit comments