Remove accept parameter for head/post again

This commit is contained in:
Philipp 2022-04-03 19:33:09 +02:00
parent 4aeccd3157
commit 04866195b4
No known key found for this signature in database
GPG key ID: 24A7501396EB5432
12 changed files with 54 additions and 57 deletions

View file

@ -59,21 +59,6 @@ interface ICanSendHttpRequests
*/
public function fetchFull(string $url, string $accept_content = HttpClientAccept::DEFAULT, int $timeout = 0, string $cookiejar = ''): ICanHandleHttpResponses;
/**
* Send a HEAD to a URL.
*
* @param string $url URL to fetch
* @param string $accept_content supply Accept: header with 'accept_content' as the value
* @param array $opts (optional parameters) associative array with:
* 'accept_content' => (string array) supply Accept: header with 'accept_content' as the value (overrides default parameter)
* 'timeout' => int Timeout in seconds, default system config value or 60 seconds
* 'cookiejar' => path to cookie jar file
* 'header' => header array
*
* @return ICanHandleHttpResponses
*/
public function head(string $url, string $accept_content = HttpClientAccept::DEFAULT, array $opts = []): ICanHandleHttpResponses;
/**
* Send a GET to a URL.
*
@ -90,14 +75,39 @@ interface ICanSendHttpRequests
public function get(string $url, string $accept_content = HttpClientAccept::DEFAULT, array $opts = []): ICanHandleHttpResponses;
/**
* Sends a HTTP request to a given url
* Send a HEAD to a URL.
*
* @param string $url URL to fetch
* @param array $opts (optional parameters) associative array with:
* 'accept_content' => (string array) supply Accept: header with 'accept_content' as the value (overrides default parameter)
* 'timeout' => int Timeout in seconds, default system config value or 60 seconds
* 'cookiejar' => path to cookie jar file
* 'header' => header array
*
* @return ICanHandleHttpResponses
*/
public function head(string $url, array $opts = []): ICanHandleHttpResponses;
/**
* Send POST request to an URL
*
* @param string $url URL to post
* @param mixed $params array of POST variables
* @param array $headers HTTP headers
* @param int $timeout The timeout in seconds, default system config value or 60 seconds
*
* @return ICanHandleHttpResponses The content
*/
public function post(string $url, $params, array $headers = [], int $timeout = 0): ICanHandleHttpResponses;
/**
* Sends an HTTP request to a given url
*
* @param string $method A HTTP request
* @param string $url Url to send to
* @param string $accept_content supply Accept: header with 'accept_content' as the value
* @param array $opts (optional parameters) associative array with:
* 'body' => (mixed) setting the body for sending data
* 'accept_content' => (string array) supply Accept: header with 'accept_content' as the value (overrides default parameter)
* 'accept_content' => (string array) supply Accept: header with 'accept_content' as the value
* 'timeout' => int Timeout in seconds, default system config value or 60 seconds
* 'cookiejar' => path to cookie jar file
* 'header' => header array
@ -106,20 +116,7 @@ interface ICanSendHttpRequests
*
* @return ICanHandleHttpResponses
*/
public function request(string $method, string $url, string $accept_content = HttpClientAccept::DEFAULT, array $opts = []): ICanHandleHttpResponses;
/**
* Send POST request to an URL
*
* @param string $url URL to post
* @param mixed $params array of POST variables
* @param string $accept_content supply Accept: header with 'accept_content' as the value
* @param array $headers HTTP headers
* @param int $timeout The timeout in seconds, default system config value or 60 seconds
*
* @return ICanHandleHttpResponses The content
*/
public function post(string $url, $params, string $accept_content = HttpClientAccept::DEFAULT, array $headers = [], int $timeout = 0): ICanHandleHttpResponses;
public function request(string $method, string $url, array $opts = []): ICanHandleHttpResponses;
/**
* Returns the original URL of the provided URL

View file

@ -63,7 +63,7 @@ class HttpClient implements ICanSendHttpRequests
/**
* {@inheritDoc}
*/
public function request(string $method, string $url, string $accept_content = HttpClientAccept::DEFAULT, array $opts = []): ICanHandleHttpResponses
public function request(string $method, string $url, array $opts = []): ICanHandleHttpResponses
{
$this->profiler->startRecording('network');
$this->logger->debug('Request start.', ['url' => $url, 'method' => $method]);
@ -141,7 +141,8 @@ class HttpClient implements ICanSendHttpRequests
};
if (empty($conf[HttpClientOptions::HEADERS]['Accept'])) {
$conf[HttpClientOptions::HEADERS]['Accept'] = $accept_content;
$this->logger->info('Accept header was missing, using default.', ['url' => $url, 'callstack' => System::callstack()]);
$conf[HttpClientOptions::HEADERS]['Accept'] = HttpClientAccept::DEFAULT;
}
try {
@ -167,9 +168,9 @@ class HttpClient implements ICanSendHttpRequests
/** {@inheritDoc}
*/
public function head(string $url, string $accept_content = HttpClientAccept::DEFAULT, array $opts = []): ICanHandleHttpResponses
public function head(string $url, array $opts = []): ICanHandleHttpResponses
{
return $this->request('head', $url, $accept_content, $opts);
return $this->request('head', $url, $opts);
}
/**
@ -177,13 +178,16 @@ class HttpClient implements ICanSendHttpRequests
*/
public function get(string $url, string $accept_content = HttpClientAccept::DEFAULT, array $opts = []): ICanHandleHttpResponses
{
return $this->request('get', $url, $accept_content, $opts);
// In case there is no
$opts[HttpClientOptions::ACCEPT_CONTENT] = $opts[HttpClientOptions::ACCEPT_CONTENT] ?? $accept_content;
return $this->request('get', $url, $opts);
}
/**
* {@inheritDoc}
*/
public function post(string $url, $params, string $accept_content = HttpClientAccept::DEFAULT, array $headers = [], int $timeout = 0): ICanHandleHttpResponses
public function post(string $url, $params, array $headers = [], int $timeout = 0): ICanHandleHttpResponses
{
$opts = [];
@ -197,7 +201,7 @@ class HttpClient implements ICanSendHttpRequests
$opts[HttpClientOptions::TIMEOUT] = $timeout;
}
return $this->request('post', $url, $accept_content, $opts);
return $this->request('post', $url, $opts);
}
/**