@@ -77,15 +77,50 @@ public function handleRequest(RequestInterface $request, callable $next, callabl
77
77
return $ first ($ request );
78
78
};
79
79
80
- return $ this ->plugin ->handleRequest ($ request , $ wrappedNext , $ wrappedFirst )->then (function (ResponseInterface $ response ) use ($ profile ) {
80
+ return $ this ->plugin ->handleRequest ($ request , $ wrappedNext , $ wrappedFirst )->then (function (ResponseInterface $ response ) use ($ profile, $ request , $ stack ) {
81
81
$ profile ->setResponse ($ this ->formatter ->formatResponse ($ response ));
82
+ $ this ->collectRequestInformation ($ request , $ stack );
82
83
83
84
return $ response ;
84
- }, function (Exception $ exception ) use ($ profile ) {
85
+ }, function (Exception $ exception ) use ($ profile, $ request , $ stack ) {
85
86
$ profile ->setFailed (true );
86
87
$ profile ->setResponse ($ this ->formatter ->formatException ($ exception ));
88
+ $ this ->collectRequestInformation ($ request , $ stack );
87
89
88
90
throw $ exception ;
89
91
});
90
92
}
93
+
94
+ /**
95
+ * Collect request information when not already done by the HTTP client. This happens when using the CachePlugin
96
+ * and the cache is hit without re-validation.
97
+ *
98
+ * @param RequestInterface $request
99
+ * @param Stack|null $stack
100
+ */
101
+ private function collectRequestInformation (RequestInterface $ request , Stack $ stack = null )
102
+ {
103
+ if (null === $ stack ) {
104
+ return ;
105
+ }
106
+
107
+ if (empty ($ stack ->getRequestTarget ())) {
108
+ $ stack ->setRequestTarget ($ request ->getRequestTarget ());
109
+ }
110
+ if (empty ($ stack ->getRequestMethod ())) {
111
+ $ stack ->setRequestMethod ($ request ->getMethod ());
112
+ }
113
+ if (empty ($ stack ->getRequestScheme ())) {
114
+ $ stack ->setRequestScheme ($ request ->getUri ()->getScheme ());
115
+ }
116
+ if (empty ($ stack ->getRequestHost ())) {
117
+ $ stack ->setRequestHost ($ request ->getUri ()->getHost ());
118
+ }
119
+ if (empty ($ stack ->getClientRequest ())) {
120
+ $ stack ->setClientRequest ($ this ->formatter ->formatRequest ($ request ));
121
+ }
122
+ if (empty ($ stack ->getCurlCommand ())) {
123
+ $ stack ->setCurlCommand ($ this ->formatter ->formatAsCurlCommand ($ request ));
124
+ }
125
+ }
91
126
}
0 commit comments