jpcaparas / laravel-http-socks5
Extends the Laravel HTTP service to allow for easy SOCKS5 proxying and provides the ability to debug the response.
v0.1.3
2025-01-03 20:18 UTC
Requires
- php: ^8.1
- guzzlehttp/guzzle: ^7.0
- laravel/framework: ^9.0|^10.0|^11.0
Requires (Dev)
- larastan/larastan: *
- laravel/pint: ^1.19
- orchestra/testbench: *
- phpunit/phpunit: ^9.0|^10.0
README
This package extends the Laravel HTTP service to allow for easy, parameterised SOCKS5 proxying
Installation
You can install the package via composer:
composer require jpcaparas/laravel-http-socks5
Usage
Registering the Service Provider
Add the service provider to your config/app.php
:
'providers' => [ // ... JPCaparas\Socks5Proxy\Socks5ProxyServiceProvider::class, ],
Setting up the SOCKS5 Proxy
To use the SOCKS5 proxy, you can utilize the fluent interface:
use Illuminate\Support\Facades\Http; $response = Http::socks5() ->setHost('proxy.example.com') ->setPort(1080) ->setCredentials('username', 'password') ->get('http://example.com');
Method Chaining
You can chain multiple configuration methods:
use Illuminate\Support\Facades\Http; $client = Http::socks5() ->setHost('proxy.example.com') ->setCredentials('username', 'password') ->withOptions([ 'debug' => true, 'timeout' => 30 ]); $response = $client->post('https://api.example.com/data', [ 'key' => 'value' ]);
Debugging the Response
Enable debugging to see detailed connection information:
use Illuminate\Support\Facades\Http; $response = Http::socks5() ->setHost('proxy.example.com') ->setCredentials('username', 'password') ->withOptions(['debug' => true]) ->get('http://example.com');
Tests
composer test
Trying it out
You can experiment with the package using Laravel Tinker. First, run:
composer tinker
Then try this example (outputs detailed connection info):
$client = \Illuminate\Support\Facades\Http::socks5() ->setHost('amsterdam.nl.socks.nordhold.net') ->setCredentials('username', 'password'); $client->withOptions(['debug' => true])->get('https://www.google.com');
Example output:
* Host amsterdam.nl.socks.nordhold.net:1080 was resolved.
* IPv6: (none)
* IPv4: [REDACTED]
* Trying [REDACTED]:1080...
* Host www.google.com:443 was resolved.
* IPv6: [REDACTED]
* IPv4: [REDACTED]
* SOCKS5 connect to [REDACTED]:443 (locally resolved)
* SOCKS5 request granted.
* Connected to amsterdam.nl.socks.nordhold.net port 1080
[...]
* SSL connection using TLSv1.3
* Server certificate verified
> GET / HTTP/1.1
Host: www.google.com
[...]
< HTTP/1.1 200 OK
< Date: Fri, 03 Jan 2025 08:14:37 GMT
[...]