Skip to content

Commit 41542f1

Browse files
authored
Merge pull request #26 from rtp-cgs/feature/curl-proxy-option
Feature/curl proxy option
2 parents ad05dc7 + ba2156e commit 41542f1

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

Classes/RequestMethod/CurlPostWithProxy.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,17 @@ public function injectSettings(array $settings)
6363
throw new \Exception("Invalid configuration, the Wegmeister.Recaptcha.httpProxy option has to be a string.");
6464
}
6565

66-
$httpProxyParts = explode(':', $settings['httpProxy']);
67-
if(count($httpProxyParts) !== 2 || (int)$httpProxyParts[1] === 0){
66+
$httpProxy = $settings['httpProxy'];
67+
$this->emitHttpProxyRetrieved($httpProxy);
68+
69+
$formatIsValid = preg_match('@^(.*):(\d{1,5})$@', $httpProxy, $httpProxyParts);
70+
$this->proxyHost = $httpProxyParts[1];
71+
$this->proxyPort = (int)$httpProxyParts[2];
72+
73+
if(!$formatIsValid || !$this->proxyHost || !$this->proxyPort){
6874
throw new \Exception("Invalid configuration, the Wegmeister.Recaptcha.httpProxy option should have the following format: 'http://yourproxy.com:1234'");
6975
}
7076

71-
$this->proxyHost = $httpProxyParts[0];
72-
$this->proxyPort = $httpProxyParts[1];
73-
7477
$this->settings = $settings;
7578
}
7679

@@ -110,9 +113,6 @@ public function submit(RequestParameters $params)
110113
CURLOPT_SSL_VERIFYPEER => true,
111114
];
112115

113-
$httpProxy = $this->settings['httpProxy'];
114-
$this->emitHttpProxyRetrieved($httpProxy);
115-
116116
$options[CURLOPT_RETURNTRANSFER] = 1;
117117
$options[CURLOPT_PROXY] = $this->proxyHost;
118118
$options[CURLOPT_PROXYPORT] = $this->proxyPort;

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,17 @@ composer require wegmeister/recaptcha
1515

1616
Afterwards, go to [http://www.google.com/recaptcha](http://www.google.com/recaptcha) and create a key for your website. Select the API version you wish to use based on the list above.
1717

18+
## Configuration
19+
20+
### HTTP Proxy
21+
If you are using a http proxy on your server you need to add this configuration:
22+
```
23+
Wegmeister:
24+
Recaptcha:
25+
requestMethod: 'Wegmeister\Recaptcha\RequestMethod\CurlPostWithProxy'
26+
httpProxy: 'http://yourproxy.com:1234'
27+
```
28+
1829
## Usage with [Neos.Form](https://github.com/neos/form)
1930

2031
Simply add the new form element to your form definition renderables:

0 commit comments

Comments
 (0)