Velvet Star Monitor

Standout celebrity highlights with iconic style.

general

What is the correct way to set and test cache control headers?

Writer Emily Wong

I am working on my OAuth login endpoint and per the spec I want to make sure that tokens don't get cached in a CDN somewhere. I need these headers set, and in addition I want to check for them in my test suite.

Cache-Control: no-store
Pragma: no-cache

1 Answer

A plug can be used to do this:

defmodule Bouncio.SessionController do use Bouncio.Web, :controller plug :secure_cache_headers ... defp secure_cache_headers(conn, _) do Plug.Conn.put_resp_header(conn, "cache-control", "no-store, private") Plug.Conn.put_resp_header(conn, "pragma", "no-cache") end
end

Testing will involve checking conn.resp_headers.

1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy