blob: 95b985cc905000c2cba9eb6c34172d071cc639c0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
<?php
# rate limiting happens in nginx
require_once __DIR__ . '/../vendor/autoload.php';
use GuzzleHttp\Client;
function resolveURL($url) {
$client = new Client();
try {
$response = $client->request('HEAD', $url, [ 'on_stats' => function( GuzzleHttp\TransferStats $stats ) use ( &$effectiveURL ){ $effectiveURL = $stats->getEffectiveUri(); }])
->getBody()->getContents();
} catch(\Exception $e) {
return $url;
}
return $effectiveURL->__toString();
}
function getURL() {
if ( empty($_REQUEST['url']) ) {
$data = json_decode(file_get_contents('php://input'), true);
return $data['url'];
} else {
return $_REQUEST['url'];
}
}
echo json_encode( ['url' => resolveURL( getURL() ) ]);
|