8000 Allow guzzle to read environment NO_PROXY variable by fbiesse · Pull Request #1197 · guzzle/guzzle · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Allow guzzle to read environment NO_PROXY variable #1197

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

Merged
merged 4 commits into from
Aug 15, 2015

Conversation

fbiesse
Copy link
@fbiesse fbiesse commented Jul 28, 2015

Avoid to use proxy if NO_PROXY is configured

@fbiesse fbiesse force-pushed the feature/no_proxy branch from ee086d3 to 0f7a462 Compare July 28, 2015 18:00
@@ -172,6 +172,11 @@ private function configureDefaults(array $config)
$defaults['proxy']['https'] = $proxy;
}

if ($noProxy = getenv('NO_PROXY')) {
$cleanedNoProxy = preg_replace('/\s/', '', $noProxy);
Copy link
Member

Choose a reason for hiding this comment

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

can you use 4 spaces?

@mtdowling
Copy link
Member

We should match what other clients are doing with NO_PROXY. For example: https://github.com/kennethreitz/requests/pull/945/files

cURL says this:

list of host names that shouldn't go through any proxy. If set to a asterisk '*' only, it matches all hosts.

So adding support for * might be nice.

wget says:

no_proxy: This variable should contain a comma-separated list of domain extensions proxy should not be used for. For instance, if the value of no_proxy is ‘.mit.edu’, proxy will not be used to retrieve documents from MIT.

This makes me think we should make it match if the host ends with any value in the CSV list of NO_PROXY servers to match wget and Requests.

@mtdowling mtdowling added this to the 6.1.0 milestone Jul 30, 2015
@fbiesse
8000
Copy link
Author
fbiesse commented Aug 6, 2015

I add support to subdomains and wilcards @mtdowling

@@ -172,6 +172,11 @@ private function configureDefaults(array $config)
$defaults['proxy']['https'] = $proxy;
}

if ($noProxy = getenv('NO_PROXY')) {
$cleanedNoProxy = preg_replace('/\s/', '', $noProxy);
Copy link
Member

Choose a reason for hiding this comment

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

I think this should just be str_replace(' ', '', $noProxy);

Copy link
Author

Choose a reason for hiding this comment

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

Me too, but it was just to avoid tab

10000
Copy link
Contributor

Choose a reason for hiding this comment

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

It may be better to use trim function?

php > var_dump(trim(" \t "));
string(0) ""

If no why only spaces will be removed?

Copy link
Author

Choose a reason for hiding this comment

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

Yes, sure, but I don't know if it is the best solution. On these lines, I remove all spaces / tabs of a list of coma separated string. So my first solution allow to remove all spaces on the string. Your just remove spaces on the begining and at the end, not all.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry did not see

$defaults['proxy']['no'] = explode(',', $cleanedNoProxy);

Then preg_replace isn't so bad.

Copy link
Member

Choose a reason for hiding this comment

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

Me too, but it was just to avoid tab

I get removing spaces, but I don't think it's necessary to remove tabs here.

$areaToMatch = "*$area";
}
// Use wilcards
$delimiter = '#';
Copy link
Contributor

Choose a reason for hiding this comment

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

Any advantages of using this delimeter instead of the standard?

@mtdowling mtdowling merged commit b8e2108 into guzzle:master Aug 15, 2015
@mtdowling
Copy link
Member

I've cleaned this up a bit and merged it. I removed all of the regex stuff and made sure that proxy rules are applied for both curl and the PHP stream wrapper. In order to achieve this, I moved the no_proxy matching code into functions.php.

@andig
Copy link
andig commented Sep 16, 2015

Love this bit. Any chance of backporting to 5.3 for those stuck with php 5.4?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
0