Google News
logo
Symfony - Interview Questions
What is Safe Content Preference in Symfony?
Some web sites have a "safe" mode to assist those who don't want to be exposed to content to which they might object. The RFC 8674 specification defines a way for user agents to ask for safe content to a server.
 
The specification does not define what content might be considered objectionable, so the concept of "safe" is not precisely defined. Rather, the term is interpreted by the server and within the scope of each web site that chooses to act upon this information.
 
Symfony offers two methods to interact with this preference :
 
* preferSafeContent();
* setContentSafe();

The following example shows how to detect if the user agent prefers "safe" content :
if ($request->preferSafeContent()) {
    $response = new Response($alternativeContent);
    // this informs the user we respected their preferences
    $response->setContentSafe();

    return $response;
Advertisement