Bird
0
0

How can you combine Flask-Talisman with a custom after_request function to add an additional header X-Custom-Header without overwriting Talisman's headers?

hard📝 Application Q9 of 15
Flask - Security Best Practices
How can you combine Flask-Talisman with a custom after_request function to add an additional header X-Custom-Header without overwriting Talisman's headers?
ADefine after_request to add header and call Talisman(app) before it
BSet X-Custom-Header inside Talisman configuration only
CUse after_request to replace all headers including Talisman ones
DAdd X-Custom-Header in before_request instead
Step-by-Step Solution
Solution:
  1. Step 1: Understand Talisman header injection

    Talisman adds headers after request processing but before response is sent.
  2. Step 2: Add custom header in after_request

    Defining an after_request function that adds headers after Talisman ensures both sets coexist.
  3. Final Answer:

    Define after_request to add header and call Talisman(app) before it -> Option A
  4. Quick Check:

    Use after_request to add headers alongside Talisman [OK]
Quick Trick: Add custom headers in after_request after Talisman setup [OK]
Common Mistakes:
MISTAKES
  • Replacing all headers in after_request
  • Trying to set custom header only in Talisman config
  • Using before_request which is too early

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Flask Quizzes