How to check for the existence of a response header in Nginx rules?

Solution 1:

Looks like someone asked this on Stack Overflow, and there is a variable for each sent header called $sent_http_my_custom_header.

See https://web.archive.org/web/20140606142058/http://wiki.nginx.org/HttpCoreModule#.24sent_http_HEADER for the details.

Reference: https://stackoverflow.com/questions/12431496/nginx-read-custom-header-from-upstream-server

Solution 2:

I guess you want something like the following in a location block:

if ($sent_http_content_length ~ '') {
    more_clear_headers Content-Type
    ...
}

See $sent_http_name

(Disclaimer: I haven't tried this; I just dug through the docs because I found the question interesting. This may or may not work)