Aerys\Request::getHeader PHP Method

getHeader() public method

If multiple headers were received for the specified field only the value of the first header is returned. Applications may use Request::getHeaderArray() to retrieve a list of all header values received for a given field. All header $field names are treated case-insensitively. A null return indicates the requested header field was not present.
public getHeader ( string $field ) : string | null
$field string
return string | null
    public function getHeader(string $field);

Usage Example

Example #1
0
 public function authorize(Request $request, Response $response)
 {
     if (!$request->getHeader("authorization")) {
         $response->setStatus(401);
         $response->setHeader("www-authenticate", "Basic realm=\"Use your ID as username and token as password!\"");
         $response->send("");
         return;
     }
     $authorization = $request->getHeader("authorization");
     $authorization = explode(" ", $authorization, 2);
     if (count($authorization) < 2) {
         $result = new Error("bad_request", "invalid authorization header", 400);
         $this->writeResponse($request, $response, $result);
         return;
     }
     switch (strtolower($authorization[0])) {
         case "token":
             break;
         case "basic":
             $authorization[1] = (string) @base64_decode($authorization[1]);
             break;
         default:
             $result = new Error("bad_request", "invalid authorization header", 400);
             $this->writeResponse($request, $response, $result);
             return;
     }
     try {
         $user = (yield resolve($this->authentication->authenticateWithToken($authorization[1])));
         $request->setLocalVar("chat.api.user", $user);
     } catch (AuthenticationException $e) {
         $result = new Error("bad_authentication", "invalid token in authorization header", 403);
         $this->writeResponse($request, $response, $result);
     }
     // a callable further down the chain will send the body
 }
All Usage Examples Of Aerys\Request::getHeader