blob: 4914cd7bbb8f607c9843b2001d1abf64777ee475 (
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
32
33
34
|
<?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) {
error_log($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'];
}
}
function resolve() {
return json_encode( ['url' => resolveURL( getURL() ) ]);
}
|