8000 Add documentation to overwrite token widget block using esi by alexander-schranz · Pull Request #10867 · symfony/symfony-docs · GitHub
[go: up one dir, main page]

Skip to content

Add documentation to overwrite token widget block using esi #10867

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add cache headers to rexample
  • Loading branch information
alexander-schranz authored Jan 12, 2019
commit 0ea3b52b33fd7a2d29350af05b361a2c123ac4a9
12 changes: 11 additions & 1 deletion http_cache/form_csrf_caching.rst
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,22 @@ You can use the ``security.csrf.token_manager`` service to generate a token for
$formName = $request->attributes->get('form');
$csrfToken = $csrfTokenManager->getToken($formName)->getValue();

return new Response(sprintf(
$response = new Response(sprintf(
'<input type="hidden" id="%s__token" name="%s[_token]" value="%s" />',
$formName,
$formName,
$csrfToken
));

// Make sure the response is not cached
$response->setPrivate();
$response->setSharedMaxAge(0);
$response->setMaxAge(0);
$response->headers->addCacheControlDirective('must-revalidate', true);
$response->headers->addCacheControlDirective('no-cache', true);
$response->headers->addCacheControlDirective('no-store', true);

return $response;
}

Another option would be to load the form via an uncached AJAX request, but
Expand Down
0