44
55namespace Windwalker \Http \Response ;
66
7+ use Psr \Http \Message \RequestInterface ;
8+ use Psr \Http \Message \ResponseInterface ;
9+ use Windwalker \Http \HttpClient ;
10+
711/**
812 * The HttpClientResponse class.
913 */
@@ -14,7 +18,23 @@ class HttpClientResponse extends Response
1418 *
1519 * @var mixed
1620 */
17- protected mixed $ info = null ;
21+ public protected(set) mixed $ info = null ;
22+
23+ public protected(set) RequestInterface $ request ;
24+
25+ protected \Closure $ curlCmdCallback ;
26+
27+ public static function fromHttpClient (
28+ RequestInterface $ request ,
29+ ResponseInterface $ response ,
30+ \Closure $ curlCmdCallback ,
31+ ): static {
32+ $ res = static ::from ($ response );
33+ $ res ->request = $ request ;
34+ $ res ->curlCmdCallback = $ curlCmdCallback ;
35+
36+ return $ res ;
37+ }
1838
1939 public function withInfo (mixed $ info ): static
2040 {
@@ -28,4 +48,20 @@ public function getInfo(): mixed
2848 {
2949 return $ this ->info ;
3050 }
51+
52+ public function getBodyString (): string
53+ {
54+ $ body = $ this ->getBody ();
55+
56+ if ($ body ->isSeekable ()) {
57+ $ body ->rewind ();
58+ }
59+
60+ return $ body ->getContents ();
61+ }
62+
63+ public function toCurlCmd (): string
64+ {
65+ return ($ this ->curlCmdCallback )();
66+ }
3167}
0 commit comments