title: How to return 404 from openresty header_filter_by_lua_block
body: <p>I have an upstream server in which I can't change anything.</p>
  <p>In my Openresty (nginx with Lua) I want to check the proxy_pass and if a certain header exists in the response then continue but if not, return 404.</p>
  <p>This is my configuration:</p>
  <pre><code>header_filter_by_lua_block {
                  local h, err = ngx.resp.get_headers()
                  local found = 0
                  for key, _ in pairs(h) do
                      if key == &quot;have-to-be-header&quot; then
                          found = 1
                      end
                      local start = string.sub(key, 1, 7)
                      if start == &quot;ToClean&quot; or start == &quot;toClean&quot; then
                          ngx.header[key] = nul
                      end
                  end
                  if found==0 then
                      ngx.status = 404
                      return ngx.exit(ngx.HTTP_NOT_FOUND)
                  end
              }
  </code></pre>
  <p>Now the behavior is that first request works, second and on hangs.</p>
  <p>Can someone please help me with the proper way to achieve this?</p>