private function insertIntoPostForms(ResponseInterface $response, callable $replace) { $html = (string) $response->getBody(); $html = preg_replace_callback('/(<form\\s[^>]*method=["\']?POST["\']?[^>]*>)/i', $replace, $html, -1, $count); if (!empty($count)) { $body = self::createStream(); $body->write($html); return $response->withBody($body); } return $response; }