Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support CURLOPT_RESOLVE option for SWOOLE_HOOK_CURL #107

Merged
merged 12 commits into from
Jul 16, 2021
Merged

Support CURLOPT_RESOLVE option for SWOOLE_HOOK_CURL #107

merged 12 commits into from
Jul 16, 2021

Conversation

sy-records
Copy link
Member

@@ -412,6 +426,15 @@ private function setOption(int $opt, $value): bool
$this->nobody = boolval($value);
$this->method = 'HEAD';
break;
case CURLOPT_RESOLVE:
foreach ((array) $value as $resolve) {
$tmpResolve = explode(':', $resolve);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

限制分割次数为3, IPV6地址里有:

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

curl的格式要求是[+]HOST:PORT:ADDRESS[,ADDRESS]...
这里没有处理前导加号也没有处理多地址

Copy link
Member Author

@sy-records sy-records May 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

看一些sdk里用到的都是一个[HOST:PORT:ADDRESS],PHP这里应该不需要支持多地址吧

PHP curl 多地址: [HOST:PORT:ADDRESS], [HOST:PORT:ADDRESS]后面的会覆盖前面的,[HOST:PORT:ADDRESS,ADDRESS]读的前面的

src/core/Curl/Handler.php Outdated Show resolved Hide resolved
@@ -412,6 +426,15 @@ private function setOption(int $opt, $value): bool
$this->nobody = boolval($value);
$this->method = 'HEAD';
break;
case CURLOPT_RESOLVE:
foreach ((array) $value as $resolve) {
$tmpResolve = explode(':', $resolve);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

curl的格式要求是[+]HOST:PORT:ADDRESS[,ADDRESS]...
这里没有处理前导加号也没有处理多地址

src/core/Curl/Handler.php Outdated Show resolved Hide resolved
tests/unit/Curl/HandlerTest.php Show resolved Hide resolved
Copy link
Member

@deminy deminy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some of following cases not yet covered.

#!/usr/bin/env bash

set -x

curl -i \
   --resolve "+httpbin.org:443:127.0.0.1" \
   https://httpbin.org/get

curl -i \
   --resolve "httpbin.org:443:127.0.0.1" \
   --resolve "httpbin.org:443:$(dig +short httpbin.org | head -n 1)" \
   https://httpbin.org/get

curl -i \
   --resolve "httpbin.org:443:$(dig +short httpbin.org | head -n 1)" \
   --resolve "+httpbin.org:443:127.0.0.1" \
   https://httpbin.org/get

curl -i \
   --resolve "httpbin.org:443:$(dig +short httpbin.org | head -n 1)" \
   --resolve "httpbin.org:443:127.0.0.1" \
   https://httpbin.org/get

curl -i \
   --resolve "httpbin.org:443:$(dig +short httpbin.org | head -n 1)" \
   --resolve "httpbin.org:443:127.0.0.1" \
   --resolve "-httpbin.org:443:127.0.0.1" \
   https://httpbin.org/get

Personally, I feel it should be fine to treat +HOST:... the same as HOST:... in the library.

@matyhtf matyhtf merged commit 05b8161 into swoole:master Jul 16, 2021
@sy-records sy-records deleted the curl-10203 branch July 16, 2021 06:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

missing CURLOPT_RESOLVE on curl hook
4 participants