@@ -76,12 +76,12 @@ private static function prepareRequest(?string $method, ?string $url, array $opt
76
76
unset($ options ['json ' ]);
77
77
78
78
if (!isset ($ options ['normalized_headers ' ]['content-type ' ])) {
79
- $ options ['normalized_headers ' ]['content-type ' ] = [$ options [ ' headers ' ][] = 'Content-Type: application/json ' ];
79
+ $ options ['normalized_headers ' ]['content-type ' ] = ['Content-Type: application/json ' ];
80
80
}
81
81
}
82
82
83
83
if (!isset ($ options ['normalized_headers ' ]['accept ' ])) {
84
- $ options ['normalized_headers ' ]['accept ' ] = [$ options [ ' headers ' ][] = 'Accept: */* ' ];
84
+ $ options ['normalized_headers ' ]['accept ' ] = ['Accept: */* ' ];
85
85
}
86
86
87
87
if (isset ($ options ['body ' ])) {
@@ -92,7 +92,6 @@ private static function prepareRequest(?string $method, ?string $url, array $opt
92
92
&& ('' !== $ h || ('' !== $ options ['body ' ] && !isset ($ options ['normalized_headers ' ]['transfer-encoding ' ])))
93
93
) {
94
94
$ options ['normalized_headers ' ]['content-length ' ] = [substr_replace ($ h ?: 'Content-Length: ' , \strlen ($ options ['body ' ]), 16 )];
95
- $ options ['headers ' ] = array_merge (...array_values ($ options ['normalized_headers ' ]));
96
95
}
97
96
}
98
97
@@ -134,11 +133,11 @@ private static function prepareRequest(?string $method, ?string $url, array $opt
134
133
if (null !== $ url ) {
135
134
// Merge auth with headers
136
135
if (($ options ['auth_basic ' ] ?? false ) && !($ options ['normalized_headers ' ]['authorization ' ] ?? false )) {
137
- $ options ['normalized_headers ' ]['authorization ' ] = [$ options [ ' headers ' ][] = 'Authorization: Basic ' .base64_encode ($ options ['auth_basic ' ])];
136
+ $ options ['normalized_headers ' ]['authorization ' ] = ['Authorization: Basic ' .base64_encode ($ options ['auth_basic ' ])];
138
137
}
139
138
// Merge bearer with headers
140
139
if (($ options ['auth_bearer ' ] ?? false ) && !($ options ['normalized_headers ' ]['authorization ' ] ?? false )) {
141
- $ options ['normalized_headers ' ]['authorization ' ] = [$ options [ ' headers ' ][] = 'Authorization: Bearer ' .$ options ['auth_bearer ' ]];
140
+ $ options ['normalized_headers ' ]['authorization ' ] = ['Authorization: Bearer ' .$ options ['auth_bearer ' ]];
142
141
}
143
142
144
143
unset($ options ['auth_basic ' ], $ options ['auth_bearer ' ]);
@@ -161,6 +160,14 @@ private static function prepareRequest(?string $method, ?string $url, array $opt
161
160
162
161
$ options ['max_duration ' ] = isset ($ options ['max_duration ' ]) ? (float ) $ options ['max_duration ' ] : 0 ;
163
162
163
+ if (isset ($ options ['normalized_headers ' ]['content-length ' ]) && $ contentType = $ options ['normalized_headers ' ]['content-type ' ] ?? null ) {
164
+ // Move Content-Type after Content-Length, see https://bugs.php.net/44603
165
+ unset($ options ['normalized_headers ' ]['content-type ' ]);
166
+ $ options ['normalized_headers ' ]['content-type ' ] = $ contentType ;
167
+ }
168
+
169
+ $ options ['headers ' ] = array_merge (...array_values ($ options ['normalized_headers ' ]));
170
+
164
171
return [$ url , $ options ];
165
172
}
166
173
0 commit comments