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()
6464 /**
6565 * The response headers
6666 *
67+ * @param bool $assoc
68+ *
6769 * @return array
6870 */
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 )
7090 {
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+ );
72111 }
73- }
112+ }
You can’t perform that action at this time.
0 commit comments