diff --git a/core/modules/rest/src/Tests/RESTTestBase.php b/core/modules/rest/src/Tests/RESTTestBase.php index 6279b35..ec91103 100644 --- a/core/modules/rest/src/Tests/RESTTestBase.php +++ b/core/modules/rest/src/Tests/RESTTestBase.php @@ -147,90 +147,65 @@ protected function httpRequest($url, $method, $body = NULL, $mime_type = NULL) { $url = $this->buildUrl($url); $curl_options = array(); + $options = [ + 'http_errors' => FALSE, + 'curl' => $this->cookieCurlOptions() + [ + CURLOPT_COOKIEJAR => $this->cookieFile, + CURLOPT_HEADERFUNCTION => [&$this, 'curlHeaderCallback'], + ], + ]; switch ($method) { case 'GET': - // Set query if there are additional GET parameters. - $options = [ - 'http_errors' => FALSE, + $options += [ 'headers' => [ 'Accept' => $mime_type, ], - 'curl' => $this->cookieCurlOptions() + [ - CURLOPT_COOKIEJAR => $this->cookieFile, - CURLOPT_HEADERFUNCTION => [&$this, 'curlHeaderCallback'], - ], ]; $response = $client->get($url, $options); break; - case 'HEAD': - $curl_options = array( - CURLOPT_HTTPGET => FALSE, - CURLOPT_CUSTOMREQUEST => 'HEAD', - CURLOPT_URL => $url, - CURLOPT_NOBODY => TRUE, - CURLOPT_HTTPHEADER => array('Accept: ' . $mime_type), - ); - break; + case 'HEAD': + $response = $client->head($url, $options); + break; case 'POST': - $options = [ - 'http_errors' => FALSE, + $options += [ 'headers' => [ 'Content-Type' => $mime_type, 'X-CSRF-Token' => $token ], - 'curl' => $this->cookieCurlOptions() + [ - CURLOPT_COOKIEJAR => $this->cookieFile, - CURLOPT_HEADERFUNCTION => [&$this, 'curlHeaderCallback'], - ], 'body' => $body, ]; $response = $client->post($url, $options); break; case 'PUT': - $options = [ - 'http_errors' => FALSE, + $options += [ 'headers' => [ 'Content-Type' => $mime_type, 'X-CSRF-Token' => $token ], - 'curl' => $this->cookieCurlOptions() + [ - CURLOPT_COOKIEJAR => $this->cookieFile, - CURLOPT_HEADERFUNCTION => [&$this, 'curlHeaderCallback'], - ], 'body' => $body, ]; $response = $client->put($url, $options); break; case 'PATCH': - $options = [ - 'http_errors' => FALSE, + $options += [ 'headers' => [ 'Content-Type' => $mime_type, 'X-CSRF-Token' => $token ], - 'curl' => $this->cookieCurlOptions() + [ - CURLOPT_COOKIEJAR => $this->cookieFile, - CURLOPT_HEADERFUNCTION => [&$this, 'curlHeaderCallback'], - ], 'body' => $body, ]; $response = $client->patch($url, $options); break; case 'DELETE': - $options = [ - 'http_errors' => FALSE, + $options += [ 'headers' => [ 'X-CSRF-Token' => $token ], - 'curl' => $this->cookieCurlOptions() + [ - CURLOPT_COOKIEJAR => $this->cookieFile, - CURLOPT_HEADERFUNCTION => [&$this, 'curlHeaderCallback'], - ], ]; $response = $client->delete($url, $options); break;