@@ -209,26 +209,26 @@ public function parse_response($response){
209
209
$ this ->response_status_lines = [];
210
210
$ line = strtok ($ response , "\n" );
211
211
do {
212
- if (strpos ($ line , 'HTTP ' ) === 0 ){
213
- // One or more HTTP status lines
214
- $ this ->response_status_lines [] = trim ($ line );
215
- }
216
- elseif (strlen (trim ($ line )) == 0 ){
212
+ if (strlen (trim ($ line )) == 0 ){
217
213
// Since we tokenize on \n, use the remaining \r to detect empty lines.
218
214
if (count ($ headers ) > 0 ) break ; // Must be the newline after headers, move on to response body
219
215
}
216
+ elseif (strpos ($ line , 'HTTP ' ) === 0 ){
217
+ // One or more HTTP status lines
218
+ $ this ->response_status_lines [] = trim ($ line );
219
+ }
220
220
else {
221
221
// Has to be a header
222
222
list ($ key , $ value ) = explode (': ' , $ line , 2 );
223
223
$ key = trim (strtolower (str_replace ('- ' , '_ ' , $ key )));
224
224
$ value = trim ($ value );
225
225
226
- if (is_array ($ headers [$ key ]))
226
+ if (empty ($ headers [$ key ]))
227
+ $ headers [$ key ] = $ value ;
228
+ elseif (is_array ($ headers [$ key ]))
227
229
$ headers [$ key ][] = $ value ;
228
- elseif (!empty ($ headers [$ key ]))
229
- $ headers [$ key ] = [$ headers [$ key ], $ value ];
230
230
else
231
- $ headers [$ key ] = $ value ;
231
+ $ headers [$ key ] = [ $ headers [ $ key ], $ value] ;
232
232
}
233
233
} while ($ line = strtok ("\n" ));
234
234
0 commit comments