Repository navigation
Allow downloading a database through a proxy - #102
Merged
Merged
Conversation
Add the "proxy" option. Filesystem::copy() opens the source with the
default stream context, so a proxy can not be given to it and the archive
is fetched by the downloader itself when a proxy is configured.
The option takes the address of the proxy server, credentials included:
gpslab_geoip:
proxy: 'http://user:password@proxy.example.com:3128'
The http, https, tcp and ssl schemes are accepted, an application protocol
is replaced with the transport PHP expects and the credentials are moved to
the Proxy-Authorization header. A proxy of any of these schemes downloads a
database over HTTPS, PHP tunnels the request with CONNECT.
The documentation suggested to use the source URL option for a proxy, which
is the address of the database and not of the proxy. It is fixed.
Closes gpslab#95
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
PHP streams support HTTP proxies only, so a SOCKS proxy was out of reach, and they need the allow_url_fopen option, which is disabled on a hardened server. cURL has neither limitation. The extension is optional, exactly like splitbrain/php-archive: cURL is used when it is installed and PHP streams are the fallback. A SOCKS proxy given to the fallback is rejected with an explicit error instead of being ignored. The accepted proxy schemes become http, https, socks4, socks4a, socks5 and socks5h. The tcp and ssl schemes are dropped, they leaked the transport PHP streams expect into the configuration. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #95
The documentation suggested using the source URL option to go through a proxy, but that option is the address of the database, not of the proxy — hence the confusion in the issue. This adds a real
proxyoption and fixes the misleading sentence.The
http,https,socks4,socks4a,socks5andsocks5hschemes are accepted. Credentials can be a part of the address and are url decoded.How it works
Filesystem::copy()opens the source with the default stream context, so no transport option can be handed to it. The downloader now fetches the archive itself:allow_url_fopenis disabled;ext-curlis not a new requirement, it goes tosuggest. This mirrors howsplitbrain/php-archiveis already handled in the downloader: use the better tool when it is there, fall back otherwise. So the bundle keeps working down to Symfony 2.8 and PHP 7.2 with no new dependency.Backward compatibility
Downloaderinterface is untouched;MaxMindDownloadergets the proxy as an optional fourth constructor argument;The one behaviour change: the archive is no longer fetched through
Filesystem::copy().Filesystemis still used for every filesystem operation, and failures still raise itsIOException.Tests
195 tests (was 165), both download paths covered:
407challenge, so the test proves that curl sends the absolute URI in the request line and retries withProxy-Authorization— and that the downloaded archive is intact.Verified locally on the stacks the CI matrix resolves: PHP 7.2 + Symfony 2.8, PHP 8.0 + Symfony 5.2, PHP 8.3 + Symfony 7.4 and PHP 8.5 + Symfony 8.1 — tests and PHPStan green on all of them, PHP CS Fixer clean.
🤖 Generated with Claude Code