diff --git a/jobs/haproxy/spec b/jobs/haproxy/spec index e393df03..b31c96f4 100644 --- a/jobs/haproxy/spec +++ b/jobs/haproxy/spec @@ -704,7 +704,15 @@ properties: ha_proxy.backend_config: description: | Raw HAProxy config that will be added to the default HTTP + routed HTTP backend definitions, provided either as a multiline text blob or as an array of lines. - + ha_proxy.backend_config_targeted: + description: | + A map of existing backends which enables more fine-grained configuration of the backend. + example: + backend_config_targeted: + http-routers-http1: | + http-reuse aggressive + http-routers-http2: | + http-reuse safe ha_proxy.custom_http_error_files: description: | A map of status codes to errorfile contents diff --git a/jobs/haproxy/templates/haproxy.config.erb b/jobs/haproxy/templates/haproxy.config.erb index 0e52caad..a1a33775 100644 --- a/jobs/haproxy/templates/haproxy.config.erb +++ b/jobs/haproxy/templates/haproxy.config.erb @@ -869,6 +869,13 @@ backend <%= backend[:name] %> <%- if properties.ha_proxy.backend_config -%> <%= format_indented_multiline_config(p("ha_proxy.backend_config")) %> <%- end -%> + <%- backend_configs = p('ha_proxy.backend_config_targeted', {}) -%> + <%- backend_configs.keys.each do |backend_name| -%> + <%- if backend[:name] == backend_name -%> + <%= format_indented_multiline_config(backend_configs[backend_name]) -%> + <%- end -%> + <%- end -%> + <%- p('ha_proxy.custom_http_error_files', {}).keys.each do |status_code| -%> errorfile <%= status_code %> /var/vcap/jobs/haproxy/errorfiles/custom<%=status_code%>.http <%- end -%> diff --git a/spec/haproxy/templates/haproxy_config/backend_http_spec.rb b/spec/haproxy/templates/haproxy_config/backend_http_spec.rb index 94630eab..aa5897e5 100644 --- a/spec/haproxy/templates/haproxy_config/backend_http_spec.rb +++ b/spec/haproxy/templates/haproxy_config/backend_http_spec.rb @@ -40,6 +40,55 @@ end end + context 'when ha_proxy.backend_config_targeted is h1' do + let(:properties) do + { + 'backend_config_targeted' => { + 'http-routers-http1' => 'http-reuse aggressive' + } + } + end + + it 'includes the config' do + expect(backend_http1).to include('http-reuse aggressive') + end + end + + context 'when ha_proxy.backend_config_targeted is h2' do + let(:properties) do + { + 'enable_http2' => true, + 'backend_ssl' => 'verify', + 'backend_config_targeted' => { + 'http-routers-http2' => 'http-reuse safe' + } + } + end + + it 'includes the config' do + expect(backend_http2).to include('http-reuse safe') + end + end + + context 'when ha_proxy.backend_config_targeted is h1 and h2' do + let(:properties) do + { + 'enable_http2' => true, + 'backend_ssl' => 'verify', + 'disable_backend_http2_websockets' => true, + 'backend_config_targeted' => { + 'http-routers-http1' => 'http-reuse aggressive', + 'http-routers-http2' => 'http-reuse safe' + } + } + end + + it 'includes the config' do + expect(backend_http1).to include('http-reuse aggressive') + expect(backend_http2).to include('http-reuse safe') + end + end + context 'when ha_proxy.custom_http_error_files is provided' do let(:properties) do {