<% if @proxy_dest or @proxy_pass or @proxy_pass_match or @proxy_dest_match -%>

  ## Proxy rules
  ProxyRequests Off
<%- end -%>
<% if @proxy_preserve_host -%>
  ProxyPreserveHost On
<% else -%>
  ProxyPreserveHost Off
<%- end -%>
<%- if defined?(@proxy_add_headers) -%>
  <%- if @proxy_add_headers -%>
  ProxyAddHeaders On
  <%- else -%>
  ProxyAddHeaders Off
  <%- end -%>
<%- 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'].keys.sort.each do |key| -%> <%= key %>=<%= proxy['params'][key] -%>
    <%- 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'].keys.sort.each do |key| -%> <%= key %>=<%= proxy['params'][key] -%>
    <%- 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 -%>
