@@ -88,12 +88,12 @@ private static function prepareRequest(?string $method, ?string $url, array $opt
88
88
unset($ options ['json ' ]);
89
89
90
90
if (!isset ($ options ['normalized_headers ' ]['content-type ' ])) {
91
- $ options ['normalized_headers ' ]['content-type ' ] = [$ options [ ' headers ' ][] = 'Content-Type: application/json ' ];
91
+ $ options ['normalized_headers ' ]['content-type ' ] = ['Content-Type: application/json ' ];
92
92
}
93
93
}
94
94
95
95
if (!isset ($ options ['normalized_headers ' ]['accept ' ])) {
96
- $ options ['normalized_headers ' ]['accept ' ] = [$ options [ ' headers ' ][] = 'Accept: */* ' ];
96
+ $ options ['normalized_headers ' ]['accept ' ] = ['Accept: */* ' ];
97
97
}
98
98
99
99
if (isset ($ options ['body ' ])) {
@@ -104,7 +104,6 @@ private static function prepareRequest(?string $method, ?string $url, array $opt
104
104
&& ('' !== $ h || ('' !== $ options ['body ' ] && !isset ($ options ['normalized_headers ' ]['transfer-encoding ' ])))
105
105
) {
106
106
$ options ['normalized_headers ' ]['content-length ' ] = [substr_replace ($ h ?: 'Content-Length: ' , \strlen ($ options ['body ' ]), 16 )];
107
- $ options ['headers ' ] = array_merge (...array_values ($ options ['normalized_headers ' ]));
108
107
}
109
108
}
110
109
@@ -146,11 +145,11 @@ private static function prepareRequest(?string $method, ?string $url, array $opt
146
145
if (null !== $ url ) {
147
146
// Merge auth with headers
148
147
if (($ options ['auth_basic ' ] ?? false ) && !($ options ['normalized_headers ' ]['authorization ' ] ?? false )) {
149
- $ options ['normalized_headers ' ]['authorization ' ] = [$ options [ ' headers ' ][] = 'Authorization: Basic ' .base64_encode ($ options ['auth_basic ' ])];
148
+ $ options ['normalized_headers ' ]['authorization ' ] = ['Authorization: Basic ' .base64_encode ($ options ['auth_basic ' ])];
150
149
}
151
150
// Merge bearer with headers
152
151
if (($ options ['auth_bearer ' ] ?? false ) && !($ options ['normalized_headers ' ]['authorization ' ] ?? false )) {
153
- $ options ['normalized_headers ' ]['authorization ' ] = [$ options [ ' headers ' ][] = 'Authorization: Bearer ' .$ options ['auth_bearer ' ]];
152
+ $ options ['normalized_headers ' ]['authorization ' ] = ['Authorization: Bearer ' .$ options ['auth_bearer ' ]];
154
153
}
155
154
156
155
unset($ options ['auth_basic ' ], $ options ['auth_bearer ' ]);
@@ -173,6 +172,14 @@ private static function prepareRequest(?string $method, ?string $url, array $opt
173
172
174
173
$ options ['max_duration ' ] = isset ($ options ['max_duration ' ]) ? (float ) $ options ['max_duration ' ] : 0 ;
175
174
175
+ if (isset ($ options ['normalized_headers ' ]['content-length ' ]) && $ contentType = $ options ['normalized_headers ' ]['content-type ' ] ?? null ) {
176
+ // Move Content-Type after Content-Length, see https://bugs.php.net/44603
177
+ unset($ options ['normalized_headers ' ]['content-type ' ]);
178
+ $ options ['normalized_headers ' ]['content-type ' ] = $ contentType ;
179
+ }
180
+
181
+ $ options ['headers ' ] = array_merge (...array_values ($ options ['normalized_headers ' ]));
182
+
176
183
return [$ url , $ options ];
177
184
}
178
185
0 commit comments