File tree Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Original file line number Diff line number Diff line change 7
7
use ApiClients \Foundation \Middleware \MiddlewareInterface ;
8
8
use ApiClients \Foundation \Middleware \PreTrait ;
9
9
use ApiClients \Tools \Json \JsonDecodeService ;
10
+ use GuzzleHttp \Psr7 \BufferStream ;
10
11
use Psr \Http \Message \ResponseInterface ;
11
12
use React \Promise \CancellablePromiseInterface ;
12
13
use React \Stream \ReadableStreamInterface ;
@@ -47,7 +48,14 @@ public function post(
47
48
return resolve ($ response );
48
49
}
49
50
50
- return $ this ->jsonDecodeService ->decode ((string )$ response ->getBody ())->then (function ($ json ) use ($ response ) {
51
+ $ body = (string )$ response ->getBody ();
52
+ if ($ body === '' ) {
53
+ $ stream = new BufferStream (0 );
54
+ $ stream ->write ($ body );
55
+ return resolve ($ response ->withBody ($ stream ));
56
+ }
57
+
58
+ return $ this ->jsonDecodeService ->decode ($ body )->then (function ($ json ) use ($ response ) {
51
59
$ body = new JsonStream ($ json );
52
60
return resolve ($ response ->withBody ($ body ));
53
61
});
Original file line number Diff line number Diff line change @@ -49,4 +49,20 @@ public function testPostNoJson()
49
49
)
50
50
);
51
51
}
52
+
53
+ public function testPostEmpty ()
54
+ {
55
+ $ loop = Factory::create ();
56
+ $ service = new JsonDecodeService ($ loop );
57
+ $ middleware = new JsonDecodeMiddleware ($ service );
58
+ $ response = new Response (200 , [], '' );
59
+
60
+ self ::assertSame (
61
+ '' ,
62
+ (string )await (
63
+ $ middleware ->post ($ response , 'abc ' ),
64
+ $ loop
65
+ )->getBody ()
66
+ );
67
+ }
52
68
}
You can’t perform that action at this time.
0 commit comments