Skip to content

Commit d0bdb88

Browse files
committed
Extended the HttpsTransport by a verify host feature
1 parent de3a634 commit d0bdb88

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

README.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ The same mechanic is offered to perform `PUT` and `PATCH` requests wich all are
131131

132132
The following example shows the usage with a more detailed configuration.
133133

134-
#### Configuring a HTTP Transport instance
134+
#### Configuring an HTTP Transport instance
135135

136136
```{php}
137137
use ChromaX\BasicHttpClient\Request\Transport\HttpTransport;
@@ -147,7 +147,7 @@ $transport
147147
->setMaxRedirects(10);
148148
```
149149

150-
#### Configuring a HTTPS Transport instance
150+
#### Configuring an HTTPS Transport instance
151151

152152
```{php}
153153
use ChromaX\BasicHttpClient\Request\Transport\HttpsTransport;
@@ -161,6 +161,7 @@ $transport
161161
->setAllowCaching(true)
162162
->setFollowRedirects(true)
163163
->setMaxRedirects(10)
164+
->setVerifyHost(true)
164165
->setVerifyPeer(true);
165166
```
166167

src/Request/Transport/HttpsTransport.php

+26
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,37 @@
1010
class HttpsTransport extends HttpTransport
1111
{
1212

13+
/**
14+
* Whether to verify the peer SSL certificate
15+
*
16+
* @var bool
17+
*/
18+
protected $verifyHost = true;
19+
1320
/**
1421
* Whether to verify the peer SSL certificate
1522
*
1623
* @var bool
1724
*/
1825
protected $verifyPeer = true;
1926

27+
/**
28+
* @return bool
29+
*/
30+
public function getVerifyHost(): bool
31+
{
32+
return $this->verifyHost;
33+
}
34+
35+
/**
36+
* @param bool $verifyHost
37+
*/
38+
public function setVerifyHost(bool $verifyHost)
39+
{
40+
$this->verifyHost = $verifyHost;
41+
return $this;
42+
}
43+
2044
/**
2145
* @return bool
2246
*/
@@ -42,6 +66,8 @@ public function setVerifyPeer(bool $verifyPeer)
4266
public function configureCurl($curl)
4367
{
4468
parent::configureCurl($curl);
69+
// Verify host
70+
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, $this->verifyHost ? 2 : 0);
4571
// Verify peer
4672
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, $this->verifyPeer);
4773
return $this;

0 commit comments

Comments
 (0)