diff options
| author | Horus | 2021-01-15 11:18:20 +0100 |
|---|---|---|
| committer | Horus | 2021-01-15 11:18:20 +0100 |
| commit | ad6c3e31f61cfbd8273ca0ebecca821e836625aa (patch) | |
| tree | 2f5549d8c115f5ff98785757e99b13b6b3b926e5 /public/resolve.php | |
| parent | 6393afb5768bab14167ce5064e16b3d090c741ef (diff) | |
| download | untrack-ad6c3e31f61cfbd8273ca0ebecca821e836625aa.tar.gz | |
Move stuff to public/ directory.
Diffstat (limited to 'public/resolve.php')
| -rw-r--r-- | public/resolve.php | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/public/resolve.php b/public/resolve.php new file mode 100644 index 0000000..b103009 --- /dev/null +++ b/public/resolve.php @@ -0,0 +1,30 @@ +<?php +# TODO rate limiting +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() ) ]); |
