Browse Source

Add HEAD method support

Jan Oris 3 years ago
parent
commit
23cf5977a0
4 changed files with 46 additions and 4 deletions
  1. 4 0
      CHANGELOG.md
  2. 25 2
      README.md
  3. 1 1
      composer.json
  4. 16 1
      src/Builder.php

+ 4 - 0
CHANGELOG.md

@@ -2,6 +2,10 @@
 
 All Notable changes to `ixudra/curl` will be documented in this file
 
+## 6.22.0 - 2021-11-14
+### Added
+- Added HEAD request support
+
 ## 6.21.0 - 2020-09-22
 ### Added
 - withAuthorization utility method

+ 25 - 2
README.md

@@ -3,7 +3,6 @@ ixudra/curl
 
 [![Latest Version on Packagist](https://img.shields.io/packagist/v/ixudra/curl.svg?style=flat-square)](https://packagist.org/packages/ixudra/curl)
 [![license](https://img.shields.io/github/license/ixudra/curl.svg)]()
-[![StyleCI](https://styleci.io/repos/18486198/shield)](https://styleci.io/repos/18486198)
 [![Total Downloads](https://img.shields.io/packagist/dt/ixudra/curl.svg?style=flat-square)](https://packagist.org/packages/ixudra/curl)
 
 
@@ -18,7 +17,7 @@ use cURL requests and also makes your code more comprehensible.
 
 The provided functionality is completely framework-independent but also contains a Laravel service provider for easy 
 integration into your Laravel project.
- 
+
 
  > Note before posting an issue: When posting an issue for the package, always be sure to provide as much information 
  > regarding the request as possible. This includes the example cURL request you are trying to transfer into the package
@@ -272,6 +271,26 @@ Delete requests work similar to `GET` requests, but use the `delete()` method in
 ```
 
 
+### Sending HEAD requests
+
+HEAD requests work similar to `GET` requests, but use the `head()` method instead:
+
+```php
+
+    use Ixudra\Curl\Facades\Curl;
+
+    // Send a HEAD request to: http://www.foo.com/bar/1
+    $response = Curl::to('http://www.foo.com/bar/1')
+        ->head();
+    
+    // Send a HEAD request to: http://www.foo.com/bar/1?foz=baz
+    $response = Curl::to('http://www.foo.com/bar/1')
+        ->withData( array( 'foz' => 'baz' ) )
+        ->head();
+
+```
+
+
 ### Sending custom headers
 
 Sending custom headers is easy with the `withHeader()` method. Multiple calls can be chained together to add multiple headers to the request:
@@ -555,6 +574,10 @@ use the facades to access the `CurlService`.
     $response = $curlService->to('http://www.foo.com/bar')
         ->delete();
 
+    // Send a HEAD request to: http://www.foo.com/bar
+    $response = $curlService->to('http://www.foo.com/bar')
+        ->head();
+
 ```
 
 

+ 1 - 1
composer.json

@@ -1,7 +1,7 @@
 {
     "name": "ixudra/curl",
     "description": "Custom PHP Curl library for the Laravel framework - developed by Ixudra",
-    "version": "6.21.0",
+    "version": "6.22.0",
     "keywords": ["Ixudra", "Laravel", "Curl"],
     "homepage": "http://ixudra.be",
     "license": "MIT",

+ 16 - 1
src/Builder.php

@@ -20,6 +20,7 @@ class Builder {
         'POST'                  => false,
         'HTTPHEADER'            => array(),
         'SSL_VERIFYPEER'        => false,
+        'NOBODY'                => false,
         'HEADER'                => false,
     );
 
@@ -503,6 +504,20 @@ class Builder {
             ->send();
     }
 
+    /**
+     * Send a HEAD request to a URL using the specified cURL options
+     *
+     * @return mixed
+     */
+    public function head()
+    {
+        $this->appendDataToURL();
+        $this->withCurlOption('NOBODY', true);
+        $this->withCurlOption('HEADER', true);
+
+        return $this->send();
+    }
+
     /**
      * Send the request
      *
@@ -665,7 +680,7 @@ class Builder {
     }
 
     /**
-     * Append set data to the query string for GET and DELETE cURL requests
+     * Append set data to the query string for GET, HEAD and DELETE cURL requests
      *
      * @return string
      */