99use Psr \Http \Message \StreamFactoryInterface ;
1010use Psr \Http \Message \UploadedFileFactoryInterface ;
1111use Psr \Http \Message \UploadedFileInterface ;
12+ use Workerman \Connection \TcpConnection as WorkermanTcpConnection ;
1213use Workerman \Protocols \Http \Request as WorkermanRequest ;
1314
1415final class PsrRequestFactory implements PsrRequestFactoryInterface
@@ -20,11 +21,12 @@ public function __construct(
2021 ) {
2122 }
2223
23- public function create (WorkermanRequest $ workermanRequest ): ServerRequestInterface
24+ public function create (WorkermanTcpConnection $ workermanTcpConnection , WorkermanRequest $ workermanRequest ): ServerRequestInterface
2425 {
2526 $ request = $ this ->serverRequestFactory ->createServerRequest (
2627 $ workermanRequest ->method (),
27- $ workermanRequest ->uri ()
28+ $ workermanRequest ->uri (),
29+ $ this ->createServerParams ($ workermanTcpConnection ),
2830 );
2931
3032 /** @var array<string, string> $headers */
@@ -47,6 +49,17 @@ public function create(WorkermanRequest $workermanRequest): ServerRequestInterfa
4749 return $ request ;
4850 }
4951
52+ /**
53+ * @return array<string, string>
54+ */
55+ private function createServerParams (WorkermanTcpConnection $ workermanTcpConnection ): array
56+ {
57+ return [
58+ 'REMOTE_ADDR ' => $ workermanTcpConnection ->getRemoteIp (),
59+ 'REMOTE_PORT ' => (string ) $ workermanTcpConnection ->getRemotePort (),
60+ ];
61+ }
62+
5063 /**
5164 * @param array<string, array<string, int|string>> $files
5265 *
0 commit comments