class RequestUtil
Constants
| INTERNAL_ATTRIBUTE |
Attribute key marking a request as an internal API call (dispatched via {\Flarum\Api\Client}, e.g. when a frontend page preloads its API document) rather than a request from an external client. |
Methods
Determine if the request is an API request. We do not manually set the `Accepts` header for API requests, so we need to check the priority list to determine whether it is or not.
Whether this request was dispatched internally. Internal requests are not held to the JSON:API spec's strict query-parameter validation: a frontend page forwards the browser's query string (which may carry tracking params like `fbclid`) into the API client, and those must not 400 the page.
Determine the client's preferred content type out of the given list.
The class the forum puts on `<html>` to tell guests from signed-in users: `guest-user` or `logged-in`. Standalone pages that use `layouts/basic` pass it to the view as `actorClass`, so a theme can rely on it across them.
No description
No description
No description
Details
at
line 24
static bool
isApiRequest( ServerRequestInterface $request)
Determine if the request is an API request. We do not manually set the `Accepts` header for API requests, so we need to check the priority list to determine whether it is or not.
Normal browsing requests will have `text/html` as their preferred content type, while API will have `* / *`.
at
line 34
static bool
isHtmlRequest( ServerRequestInterface $request)
at
line 46
static ServerRequestInterface
withInternal( ServerRequestInterface $request)
at
line 57
static bool
isInternal( ServerRequestInterface $request)
Whether this request was dispatched internally. Internal requests are not held to the JSON:API spec's strict query-parameter validation: a frontend page forwards the browser's query string (which may carry tracking params like `fbclid`) into the API client, and those must not 400 the page.
at
line 69
static string
getPreferredContentType( ServerRequestInterface $request, array $types)
Determine the client's preferred content type out of the given list.
at
line 110
static string|null
getActorHtmlClass( ServerRequestInterface $request)
The class the forum puts on `<html>` to tell guests from signed-in users: `guest-user` or `logged-in`. Standalone pages that use `layouts/basic` pass it to the view as `actorClass`, so a theme can rely on it across them.
It reflects the actor as far as the request got. The reference is shared and filled in by the authentication middleware, so an error thrown before that has run (for example in `StartSession`, `RememberFromCookie`, `CollectGarbage` or an extension's middleware) still sees the `Guest` that `InjectActorReference` set first, and a signed-in visitor gets `guest-user`. That errs on the safe side. Returns null when the request has no actor reference at all.