Skip to content

Commit

Permalink
Add mod_proxy_http2 support
Browse files Browse the repository at this point in the history
This adds a module class to include the Apache module. For every vhost
it also inspects the configured proxy if the module is required.
  • Loading branch information
ekohl committed Jun 29, 2023
1 parent d6f9d34 commit 1769dbd
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 0 deletions.
9 changes: 9 additions & 0 deletions manifests/mod/proxy_http2.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# @summary
# Installs `mod_proxy_http2`.
#
# @see https://httpd.apache.org/docs/current/mod/mod_proxy_http2.html for additional documentation.
#
class apache::mod::proxy_http2 {
require apache::mod::proxy
apache::mod { 'proxy_http2': }
}
25 changes: 25 additions & 0 deletions manifests/vhost.pp
Original file line number Diff line number Diff line change
Expand Up @@ -2303,6 +2303,21 @@

if $directory['provider'] and $directory['provider'] =~ 'location' and ('proxy_pass' in $directory or 'proxy_pass_match' in $directory) {
include apache::mod::proxy_http

# To match processing in templates/vhost/_directories.erb
if $directory['proxy_pass_match'] {
Array($directory['proxy_pass_match']).each |$proxy| {
if $proxy['url'] =~ /"h2c?:\/\// {
include apache::mod::proxy_http2
}
}
} elsif $directory['proxy_pass'] {
Array($directory['proxy_pass']).each |$proxy| {
if $proxy['url'] =~ /"h2c?:\/\// {
include apache::mod::proxy_http2
}
}
}
}

if 'request_headers' in $directory {
Expand Down Expand Up @@ -2453,6 +2468,16 @@
if ($proxy_dest or $proxy_pass or $proxy_pass_match or $proxy_dest_match or $proxy_preserve_host or ($proxy_add_headers =~ NotUndef)) and $ensure == 'present' {
include apache::mod::proxy_http

# To match processing in templates/vhost/_proxy.erb
if $proxy_dest =~ Pattern[/^h2c?:\/\//] or $proxy_dest_match =~ Pattern[/^h2c?:\/\//] {
include apache::mod::proxy_http2
}
[$proxy_pass, $proxy_pass_match].flatten.each |$proxy| {
if $proxy and $proxy['url'] =~ Pattern[/^h2c?:\/\//] {
include apache::mod::proxy_http2
}
}

concat::fragment { "${name}-proxy":
target => "${priority_real}${filename}.conf",
order => 170,
Expand Down
10 changes: 10 additions & 0 deletions manifests/vhost/proxy.pp
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,16 @@
include apache::mod::proxy
include apache::mod::proxy_http

# To match processing in templates/vhost/_proxy.erb
if $proxy_dest =~ Pattern[/^h2c?:\/\//] or $proxy_dest_match =~ Pattern[/^h2c?:\/\//] {
include apache::mod::proxy_http2
}
[$proxy_pass, $proxy_pass_match].flatten.each |$proxy| {
if $proxy and $proxy['url'] =~ Pattern[/^h2c?:\/\//] {
include apache::mod::proxy_http2
}
}

unless $proxy_dest or $proxy_pass or $proxy_pass_match or $proxy_dest_match {
fail('At least one of proxy_dest, proxy_pass, proxy_pass_match or proxy_dest_match must be given')
}
Expand Down
15 changes: 15 additions & 0 deletions spec/classes/mod/proxy_http2_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

require 'spec_helper'

describe 'apache::mod::proxy_http2' do
on_supported_os.each do |os, os_facts|
context "on #{os}" do
let(:facts) { os_facts }

it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_class('apache::mod::proxy') }
it { is_expected.to contain_apache__mod('proxy_http2') }
end
end
end
50 changes: 50 additions & 0 deletions spec/defines/vhost_proxy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,56 @@
CONTENT
)
end

context 'with HTTP/2 proxy_dest URL' do
let(:params) do
super().merge(proxy_dest: 'h2://localhost:8080/')
end

it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_class('apache::mod::proxy_http2') }
end

context 'with HTTP/2 proxy_dest_match URL' do
let(:params) do
super().merge(proxy_dest_match: 'h2://localhost:8080/')
end

it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_class('apache::mod::proxy_http2') }
end

context 'with HTTP/2 proxy_pass URL' do
let(:params) do
super().merge(
proxy_pass: [
{
path: '/',
url: 'h2://localhost:8080/'
},
],
)
end

it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_class('apache::mod::proxy_http2') }
end

context 'with HTTP/2 proxy_pass_match URL' do
let(:params) do
super().merge(
proxy_pass_match: [
{
path: '/',
url: 'h2://localhost:8080/'
},
],
)
end

it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_class('apache::mod::proxy_http2') }
end
end
end
end
Expand Down

0 comments on commit 1769dbd

Please sign in to comment.