@@ -253,9 +253,21 @@ public function getFiles($key): array
253253 */
254254 public function getCookie (string $ key , string $ default = '' ): string
255255 {
256- $ key = strtolower ($ key );
256+ $ key = \strtolower ($ key );
257+
258+ $ cookies = \explode ('; ' , $ this ->getHeader ('cookie ' , '' ));
259+ foreach ($ cookies as $ cookie ) {
260+ $ cookie = \trim ($ cookie );
261+ [$ cookieKey , $ cookieValue ] = \explode ('= ' , $ cookie , 2 );
262+ $ cookieKey = \trim ($ cookieKey );
263+ $ cookieKey = \strtolower ($ cookieKey );
264+ $ cookieValue = \trim ($ cookieValue );
265+ if ($ cookieValue === $ key ) {
266+ return $ cookieValue ;
267+ }
268+ }
257269
258- return $ this -> swoole -> cookie [ $ key ] ?? $ default ;
270+ return $ default ;
259271 }
260272
261273 /**
@@ -361,17 +373,8 @@ protected function generateHeaders(): array
361373 {
362374 $ headers = $ this ->swoole ->header ;
363375
364- if (empty ($ this ->swoole ->cookie )) {
365- return $ headers ;
366- }
367-
368- $ cookieHeaders = [];
369- foreach ($ this ->swoole ->cookie as $ key => $ value ) {
370- $ cookieHeaders [] = "{$ key }= {$ value }" ;
371- }
372-
373- if (!empty ($ cookieHeaders )) {
374- $ headers ['cookie ' ] = \implode ('; ' , $ cookieHeaders );
376+ foreach ($ headers as $ key => $ value ) {
377+ $ headers [strtolower ($ key )] = $ value ;
375378 }
376379
377380 return $ headers ;
0 commit comments