Conditional return of proxied responses

Hi Nginx!

I’m using nginx-0.8.49 as a caching proxy and would like to
configure or implement the following:

Proxy incoming request to back-end servers
Check HTTP response headers for a unique string in either “Server” or
some “X-foo” lines.
IF check passes then return the response to the client
Else pass back an error message or HTTP 204.

Why?
Sometimes in systems like EC2 the backend at a given IP that used to
be yours may not be your box anymore (the IP might be reused).
Simple token-based security/sanity check that the response is coming
from your backend server.

If this can’t be configured out-of-the-box… the most logical way to
implement this is with a response filter and a nginx plug-in correct?

Thanks - Neal Richter