Skip to content

Commit

Permalink
Add option to disable h2 (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
jakolehm authored Dec 16, 2017
1 parent 2ab5102 commit 3a0e120
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/kontena/templates/haproxy/http_in.text.erb
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
listen http-in
bind *:80<% if ENV['KONTENA_LB_ACCEPT_PROXY'] %> accept-proxy<% end %>
bind *:80<% if accept_proxy? %> accept-proxy<% end %>
http-request replace-header Host (.*):.* \1
<% if ssl? %>
bind *:443 ssl crt /etc/haproxy/certs/ no-sslv3<% if ENV['KONTENA_LB_ACCEPT_PROXY'] %> accept-proxy<% end %> alpn h2,http/1.1
bind *:443 ssl crt /etc/haproxy/certs/ no-sslv3<% if accept_proxy? %> accept-proxy<% end %><% if http2? %> alpn h2,http/1.1<% end %>
reqadd X-Forwarded-Proto:\ https if { ssl_fc }
reqadd X-Forwarded-Port:\ 443 if { ssl_fc }
<% end %>

errorfile 502 /etc/haproxy/errors/502.http
errorfile 503 /etc/haproxy/errors/503.http

<% if ENV['KONTENA_LB_HEALTH_URI'] %>
monitor-uri <%= ENV['KONTENA_LB_HEALTH_URI'] %>
<% if health_uri %>
monitor-uri <%= health_uri %>
errorfile 200 /etc/haproxy/errors/200.http
<% end %>

Expand Down
14 changes: 14 additions & 0 deletions lib/kontena/views/http_in.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,19 @@ class HttpIn

format :text
template 'haproxy/http_in'

def accept_proxy?
ENV['KONTENA_LB_ACCEPT_PROXY']
end

def http2?
ENV['KONTENA_LB_HTTP2'].to_s != 'false'
end

def health_uri
if uri = ENV['KONTENA_LB_HEALTH_URI']
_raw uri
end
end
end
end
31 changes: 31 additions & 0 deletions spec/kontena/views/http_in_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,37 @@
)
expect(output.match(/alpn h2/)).to be_truthy
end

it 'allows to disable http2 support' do
allow(ENV).to receive(:[])
allow(ENV).to receive(:[]).with('KONTENA_LB_HTTP2').and_return('false')
allow(ENV).to receive(:[]).with('SSL_CERTS').and_return('certs')
output = described_class.render(
format: :text,
services: []
)
expect(output.match(/alpn h2/)).to be_falsey
end
end

context 'monitor-uri' do
it 'does not add monitor-uri by default' do
output = described_class.render(
format: :text,
services: []
)
expect(output.match(/monitor-uri/)).to be_falsey
end

it 'adds monitor-uri if health uri is set' do
allow(ENV).to receive(:[])
allow(ENV).to receive(:[]).with('KONTENA_LB_HEALTH_URI').and_return('/__health')
output = described_class.render(
format: :text,
services: []
)
expect(output.match(/monitor-uri \/__health/)).to be_truthy
end
end
end
end

0 comments on commit 3a0e120

Please sign in to comment.