@@ -49,11 +49,8 @@ public function respond(RequestContext $context, OctaneResponse $octaneResponse)
4949 );
5050 }
5151
52- if (
53- ($ octaneResponse ->response instanceof StreamedResponse) &&
54- ($ responseCallback = $ octaneResponse ->response ->getCallback ()) &&
55- ((new ReflectionFunction ($ responseCallback ))->getReturnType ()?->getName() === Generator::class)
56- ) {
52+ if (($ octaneResponse ->response instanceof StreamedResponse) &&
53+ ! is_null ($ responseCallback = static ::resolveStreamResponseCallback ($ octaneResponse ->response ))) {
5754 $ this ->client ->getHttpWorker ()->respond (
5855 $ octaneResponse ->response ->getStatusCode (),
5956 $ responseCallback (),
@@ -66,6 +63,28 @@ public function respond(RequestContext $context, OctaneResponse $octaneResponse)
6663 $ this ->client ->respond ($ this ->toPsr7Response ($ octaneResponse ->response ));
6764 }
6865
66+ /**
67+ * Resolve the stream response callback from the given response.
68+ *
69+ * @param \Symfony\Component\HttpFoundation\StreamedResponse $response
70+ * @return \Closure|null
71+ */
72+ public static function resolveStreamResponseCallback (StreamedResponse $ response )
73+ {
74+ if (is_null ($ responseCallback = $ response ->getCallback ())) {
75+ return null ;
76+ }
77+
78+ $ reflection = new ReflectionFunction ($ responseCallback );
79+
80+ if ($ reflection ->hasReturnType () === true &&
81+ in_array ($ reflection ->getReturnType ()?->getName(), [Generator::class, 'string ' ])) {
82+ return $ responseCallback ;
83+ }
84+
85+ return null ;
86+ }
87+
6988 /**
7089 * Send an error message to the server.
7190 */
0 commit comments