    auth_request_set $headername1 $upstream_http_headername1;
    auth_request_set $headervalue1 $upstream_http_headervalue1;
    auth_request_set $headername2 $upstream_http_headername2;
    auth_request_set $headervalue2 $upstream_http_headervalue2;
    auth_request_set $headername3 $upstream_http_headername3;
    auth_request_set $headervalue3 $upstream_http_headervalue3;
    auth_request_set $headername4 $upstream_http_headername4;
    auth_request_set $headervalue4 $upstream_http_headervalue4;
    auth_request_set $headername5 $upstream_http_headername5;
    auth_request_set $headervalue5 $upstream_http_headervalue5;
    auth_request_set $headername6 $upstream_http_headername6;
    auth_request_set $headervalue6 $upstream_http_headervalue6;
    auth_request_set $headername7 $upstream_http_headername7;
    auth_request_set $headervalue7 $upstream_http_headervalue7;
    auth_request_set $headername8 $upstream_http_headername8;
    auth_request_set $headervalue8 $upstream_http_headervalue8;
    auth_request_set $headername9 $upstream_http_headername9;
    auth_request_set $headervalue9 $upstream_http_headervalue9;
    auth_request_set $headername10 $upstream_http_headername10;
    auth_request_set $headervalue10 $upstream_http_headervalue10;
    auth_request_set $headername11 $upstream_http_headername11;
    auth_request_set $headervalue11 $upstream_http_headervalue11;
    auth_request_set $headername12 $upstream_http_headername12;
    auth_request_set $headervalue12 $upstream_http_headervalue12;
    auth_request_set $headername13 $upstream_http_headername13;
    auth_request_set $headervalue13 $upstream_http_headervalue13;
    auth_request_set $headername14 $upstream_http_headername14;
    auth_request_set $headervalue14 $upstream_http_headervalue14;
    auth_request_set $headername15 $upstream_http_headername15;
    auth_request_set $headervalue15 $upstream_http_headervalue15;
    auth_request_set $deleteheader1 $upstream_http_deleteheader1;
    auth_request_set $deleteheader2 $upstream_http_deleteheader2;
    auth_request_set $deleteheader3 $upstream_http_deleteheader3;
    auth_request_set $deleteheader4 $upstream_http_deleteheader4;
    auth_request_set $deleteheader5 $upstream_http_deleteheader5;
    auth_request_set $deleteheader6 $upstream_http_deleteheader6;
    auth_request_set $deleteheader7 $upstream_http_deleteheader7;
    auth_request_set $deleteheader8 $upstream_http_deleteheader8;
    auth_request_set $deleteheader9 $upstream_http_deleteheader9;
    auth_request_set $deleteheader10 $upstream_http_deleteheader10;
    auth_request_set $deleteheader11 $upstream_http_deleteheader11;
    auth_request_set $deleteheader12 $upstream_http_deleteheader12;
    auth_request_set $deleteheader13 $upstream_http_deleteheader13;
    auth_request_set $deleteheader14 $upstream_http_deleteheader14;
    auth_request_set $deleteheader15 $upstream_http_deleteheader15;
    auth_request_set $lmcookie $upstream_http_cookie;
    auth_request_set $internal_lemonldap_logout_url $upstream_http_internal_lemonldap_logout_url;
    access_by_lua '
      local i = 1
      ngx.req.set_header("Cookie",ngx.var.lmcookie)
      while true do
        if ngx.var["headername"..i] ~= nil then
          ngx.req.set_header(ngx.var["headername"..i],ngx.var["headervalue"..i])
        else
          break
        end
        i = i + 1
      end
      i = 1
      while true do
        if ngx.var["deleteheader"..i] ~= nil then
	      ngx.req.clear_header(ngx.var["deleteheader"..i])
        else
          break
        end
        i = i + 1
      end
    ';

    # For managing logout_app / logout_app_sso redirection
    # Make sure the following block is enabled in the appropriate "location" section
    header_filter_by_lua '
      if ngx.var["internal_lemonldap_logout_url"] ~= nil and ngx.var["internal_lemonldap_logout_url"] ~= "" then
        return ngx.exit(457)
      end
    ';
    # Do not drop upstream cookies for logout_app / logout_app_sso redirections
    add_header Set-Cookie $upstream_http_set_cookie always;
    # Use specific code for triggering logout_app / logout_app_sso redirections
    error_page 457 $internal_lemonldap_logout_url;
