File tree Expand file tree Collapse file tree 1 file changed +42
-3
lines changed Expand file tree Collapse file tree 1 file changed +42
-3
lines changed Original file line number Diff line number Diff line change @@ -64,10 +64,49 @@ public function body()
64
64
/**
65
65
* The response headers
66
66
*
67
+ * @param bool $assoc
68
+ *
67
69
* @return array
68
70
*/
69
- public function headers ()
71
+ public function headers ($ assoc = false )
72
+ {
73
+ if (!$ assoc ) {
74
+ return $ this ->headers ;
75
+ }
76
+
77
+ return $ this ->prettifyHeaders ($ this ->headers ):
78
+ }
79
+
80
+ /**
81
+ * Returns response headers as associative array
82
+ *
83
+ * @param array $headers
84
+ *
85
+ * @return array
86
+ *
87
+ * @throws \InvalidArgumentException
88
+ */
89
+ private function prettifyHeaders ($ headers )
70
90
{
71
- return $ this ->headers ;
91
+ if (!is_array ($ headers )) {
92
+ throw new \InvalidArgumentException ('$headers should be array ' );
93
+ }
94
+
95
+ return array_reduce (
96
+ $ headers ,
97
+ function ($ result , $ header ) {
98
+ if (false === strpos (': ' , $ header ) {
99
+ $ result ['status ' ] = $ header ;
100
+
101
+ return $ result ;
102
+ }
103
+
104
+ list ($ key , $ value ) = explode (': ' , $ header );
105
+ $ result [$ key ] = $ value ;
106
+
107
+ return $ result ;
108
+ },
109
+ []
110
+ );
72
111
}
73
- }
112
+ }
You can’t perform that action at this time.
0 commit comments