From 9660f83adb5f4b564193491803247f0fc63dfa27 Mon Sep 17 00:00:00 2001 From: butschster Date: Thu, 5 Feb 2026 10:51:22 +0400 Subject: [PATCH] feat: add generic request() method to HttpClientInterface This enables downstream consumers (e.g. MCP custom HTTP tools) to use PUT, PATCH, DELETE, HEAD, OPTIONS and any other valid HTTP method. --- src/Lib/HttpClient/HttpClientInterface.php | 13 +++++++++++++ src/Lib/HttpClient/Psr18Client.php | 13 +------------ .../Console/GenerateCommand/MockHttpClient.php | 11 +++++++++++ 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/src/Lib/HttpClient/HttpClientInterface.php b/src/Lib/HttpClient/HttpClientInterface.php index 414119c9..b40fe1b9 100644 --- a/src/Lib/HttpClient/HttpClientInterface.php +++ b/src/Lib/HttpClient/HttpClientInterface.php @@ -31,6 +31,19 @@ public function get(string $url, array $headers = []): HttpResponse; */ public function post(string $url, array $headers = [], ?string $body = null): HttpResponse; + /** + * Send a request with the specified HTTP method. + * + * @param string $method The HTTP method (GET, POST, PUT, PATCH, DELETE, etc.) + * @param string $url The URL to request + * @param array $headers Optional request headers + * @param string|null $body Optional request body + * @return HttpResponse The response object + * + * @throws HttpException If the request fails + */ + public function request(string $method, string $url, array $headers = [], ?string $body = null): HttpResponse; + /** * Send a request to the specified URL and follow redirects if needed * diff --git a/src/Lib/HttpClient/Psr18Client.php b/src/Lib/HttpClient/Psr18Client.php index 38f0257e..8ccd5e28 100644 --- a/src/Lib/HttpClient/Psr18Client.php +++ b/src/Lib/HttpClient/Psr18Client.php @@ -52,18 +52,7 @@ public function getWithRedirects(string $url, array $headers = []): HttpResponse } } - /** - * Send a request with the specified method to the URL - * - * @param string $method The HTTP method - * @param string $url The URL to request - * @param array $headers Optional request headers - * @param string|null $body Optional request body (for POST, PUT, etc.) - * @return HttpResponse The response object - * - * @throws HttpException If the request fails - */ - private function request(string $method, string $url, array $headers = [], ?string $body = null): HttpResponse + public function request(string $method, string $url, array $headers = [], ?string $body = null): HttpResponse { $request = $this->requestFactory->createRequest($method, $url); diff --git a/tests/src/Feature/Console/GenerateCommand/MockHttpClient.php b/tests/src/Feature/Console/GenerateCommand/MockHttpClient.php index 6cd15124..bde1c30b 100644 --- a/tests/src/Feature/Console/GenerateCommand/MockHttpClient.php +++ b/tests/src/Feature/Console/GenerateCommand/MockHttpClient.php @@ -44,6 +44,17 @@ public function getWithRedirects(string $url, array $headers = []): HttpResponse return $this->get($url, $headers); } + public function request(string $method, string $url, array $headers = [], ?string $body = null): HttpResponse + { + $this->requestHeaders[$url] = $headers; + + return $this->responses[$url] ?? new HttpResponse( + statusCode: 200, + body: "Mock {$method} response for {$url}", + headers: [], + ); + } + public function addResponse(string $url, HttpResponse $response): void { $this->responses[$url] = $response;