load(); $options = new Options(); try { $options->setConfig($config); $options->parse($_GET); } catch (\InvalidArgumentException $e) { header('HTTP/1.0 400 Bad Request'); header('Content-type: text/plain'); echo $e->getMessage() . "\n"; exit(1); } $auth = new Authenticator(); try { $auth->authenticate($config); } catch (\Exception $e) { header('HTTP/1.0 401 Unauthorized'); header('Content-type: text/plain'); echo $e->getMessage() . "\n"; exit(1); } $rep = new Repository(); $rep->setConfig($config); try { $img = $rep->getImage($options); header('HTTP/1.0 302 Found'); header('Location: ' . $img->getUrl()); } catch (\Exception $e) { //FIXME: handle 404s and so properly header('HTTP/1.0 500 Internal Server error'); header('Content-type: text/plain'); echo $e->getMessage() . "\n"; exit(2); } ?>