<% if @proxy_dest or @proxy_pass or @proxy_pass_match or @proxy_dest_match or defined?(@proxy_add_headers) -%>

  ## Proxy rules
  ProxyRequests <%= scope.call_function('apache::bool2httpd', @proxy_requests) %>
<%- end -%>
  ProxyPreserveHost <%= scope.call_function('apache::bool2httpd', @proxy_preserve_host) %>
<%- if defined?(@proxy_add_headers) -%>
  ProxyAddHeaders <%= scope.call_function('apache::bool2httpd', @proxy_add_headers) %>
<%- end -%>
<% if @proxy_error_override -%>
  ProxyErrorOverride On
<%- end -%>
<%- [@proxy_pass].flatten.compact.each do |proxy| -%>
  <%- Array(proxy['no_proxy_uris']).each do |uri| -%>
  ProxyPass <%= uri %> !
  <%- end -%>
  <%- Array(proxy['no_proxy_uris_match']).each do |uri| -%>
  ProxyPassMatch <%= uri %> !
  <%- end -%>
  ProxyPass <%= proxy['path'] %> <%= proxy['url'] -%>
  <%- if proxy['params'] -%>
    <%- proxy['params'].sort.each do |key, value| -%> <%= key %>=<%= value -%>
    <%- end -%>
  <%- end -%>
  <%- if proxy['keywords'] %> <%= proxy['keywords'].join(' ') -%>
  <%- end %>
  <%- if not proxy['reverse_cookies'].nil? -%>
    <%- Array(proxy['reverse_cookies']).each do |reverse_cookies| -%>
      <%- if reverse_cookies['path'] -%>
  ProxyPassReverseCookiePath <%= reverse_cookies['path'] %> <%= reverse_cookies['url'] %>
      <%- end -%>
      <%- if reverse_cookies['domain'] -%>
  ProxyPassReverseCookieDomain <%= reverse_cookies['domain'] %> <%= reverse_cookies['url'] %>
      <%- end -%>
    <%- end -%>
  <%- end -%>
  <%- if proxy['reverse_urls'].nil? -%>
  ProxyPassReverse <%= proxy['path'] %> <%= proxy['url'] %>
  <%- else -%>
    <%- Array(proxy['reverse_urls']).each do |reverse_url| -%>
  ProxyPassReverse <%= proxy['path'] %> <%= reverse_url %>
    <%- end -%>
  <%- end -%>
  <%- if proxy['setenv'] -%>
    <%- Array(proxy['setenv']).each do |setenv_var| -%>
  SetEnv <%= setenv_var %>
    <%- end -%>
  <%- end -%>
<% end -%>
<% [@proxy_pass_match].flatten.compact.each do |proxy| %>
  <%- Array(proxy['no_proxy_uris']).each do |uri| -%>
  ProxyPass <%= uri %> !
  <%- end -%>
  <%- Array(proxy['no_proxy_uris_match']).each do |uri| -%>
  ProxyPassMatch <%= uri %> !
  <%- end -%>
  ProxyPassMatch <%= proxy['path'] %> <%= proxy['url'] -%>
  <%- if proxy['params'] -%>
    <%- proxy['params'].sort.each do |key, value| -%> <%= key %>=<%= value -%>
    <%- end -%>
  <%- end -%>
  <%- if proxy['keywords'] %> <%= proxy['keywords'].join(' ') -%>
  <%- end %>
  <%- if proxy['reverse_urls'].nil? -%>
  ProxyPassReverse <%= proxy['path'] %> <%= proxy['url'] %>
  <%- else -%>
    <%- Array(proxy['reverse_urls']).each do |reverse_url| -%>
  ProxyPassReverse <%= proxy['path'] %> <%= reverse_url %>
    <%- end -%>
  <%- end -%>
  <%- if proxy['setenv'] -%>
    <%- Array(proxy['setenv']).each do |setenv_var| -%>
  SetEnv <%= setenv_var %>
    <%- end -%>
  <%- end -%>
<% end -%>
<% if @proxy_dest -%>
<%- Array(@no_proxy_uris).each do |uri| -%>
  ProxyPass        <%= uri %> !
<% end -%>
  ProxyPass        / <%= @proxy_dest %>/
  ProxyPassReverse / <%= @proxy_dest %>/
<% end -%>
<% if @proxy_dest_match -%>
<%- Array(@no_proxy_uris_match).each do |uri| -%>
  ProxyPassMatch   <%= uri %> !
<% end -%>
  ProxyPassMatch   / <%= @proxy_dest_match %>/
  ProxyPassReverse / <%= @proxy_dest_reverse_match %>/
<% end -%>
