Explorar o código

Added support for multiple response headers with the same name

Jan Oris %!s(int64=5) %!d(string=hai) anos
pai
achega
ef5563b9a9
Modificáronse 3 ficheiros con 26 adicións e 12 borrados
  1. 4 0
      CHANGELOG.md
  2. 1 1
      composer.json
  3. 21 11
      src/Builder.php

+ 4 - 0
CHANGELOG.md

@@ -2,6 +2,10 @@
 
 All Notable changes to `ixudra/curl` will be documented in this file
 
+## 6.17.0 - 2019-09-13
+### Added
+- Added support for multiple response headers with the same name
+
 ## 6.16.0 - 2017-12-07
 ### Added
 - Added method to return response headers in the response objects

+ 1 - 1
composer.json

@@ -1,7 +1,7 @@
 {
     "name": "ixudra/curl",
     "description": "Custom PHP Curl library for the Laravel 5 framework - developed by Ixudra",
-    "version": "6.16.0",
+    "version": "6.17.0",
     "keywords": ["Ixudra", "Laravel", "Curl"],
     "homepage": "http://ixudra.be",
     "license": "MIT",

+ 21 - 11
src/Builder.php

@@ -534,19 +534,29 @@ class Builder {
                 return [ $arr[ 0 ] => $arr[ 1 ] ];
             }
         }, array_filter(array_map('trim', explode("\r\n", $headerString)))));
-        
-        $return = [];
-            
-        foreach($headers as $val){
-            $key = array_keys($val)[0];
-            if(isset($return[$key])){
-                $return[$key] = array_merge((array) $return[$key], [array_values($val)[0]]);
-            }else{
-                $return = array_merge($return, $val);
+
+        $results = [];
+
+        foreach( $headers as $values ) {
+            if( !is_array($values) ) {
+                continue;
+            }
+
+            $key = array_keys($values)[ 0 ];
+            if( isset($results[ $key ]) ) {
+                $results[ $key ] = array_merge(
+                    (array) $results[ $key ],
+                    array( array_values($values)[ 0 ] )
+                );
+            } else {
+                $results = array_merge(
+                    $results,
+                    $values
+                );
             }
         }
-    
-        return $return;    
+
+        return $results;
     }
 
     /**