protected function _run($request)
 {
     if ($this->requestMethod == 'POST' && count($request) == 0) {
         // User tries to login
         Authentication::login($_POST['username'], $_POST['password']);
         if (!Authentication::authenticated()) {
             Headers::sendStatusUnauthorized();
             return;
         } else {
             Headers::sendStatusOk();
             echo "login succeeded<br>";
             return;
         }
     } else {
         Authentication::authenticate();
         if (!Authentication::authenticated()) {
             Headers::sendStatusUnauthorized();
             return;
         }
         if ($this->requestMethod == 'GET' && count($request) > 0) {
             // User info requested
             echo "requesting userinfo of user " . $request[0];
         } else {
             // Bad request
             Headers::sendStatusMethodNotAllowed();
             echo "Method not allowed<br>";
             print_r($request);
         }
     }
 }
 public function __construct($request)
 {
     $this->_setRequestMethod();
     Authentication::authenticate();
     if (!Authentication::authenticated()) {
         // Return unauthorised response
         Headers::sendStatusUnauthorised();
         echo "Unauthorised<br>";
         return;
     }
     $this->_run($request);
 }