Skip to content

Commit

Permalink
Merge pull request #2393 from ekohl/mod_proxy_http2
Browse files Browse the repository at this point in the history
Add mod_proxy_http2 support
  • Loading branch information
jordanbreen28 authored Jun 29, 2023
2 parents 1f0f3e1 + 1769dbd commit 6ef5fbf
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 1 deletion.
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
15 changes: 15 additions & 0 deletions spec/classes/mod/proxy_http_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_http' 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_http') }
end
end
end
54 changes: 53 additions & 1 deletion spec/defines/vhost_proxy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
it { is_expected.to compile.and_raise_error(%r{At least one of}) }
end

context 'with proxy_dest' do
context 'with proxy_pass' do
let(:params) do
super().merge(
proxy_pass: [
Expand All @@ -37,6 +37,8 @@

it 'creates a concat fragment' do
expect(subject).to compile.with_all_deps
expect(subject).to contain_class('apache::mod::proxy')
expect(subject).to contain_class('apache::mod::proxy_http')
expect(subject).to contain_concat('15-default-80.conf')
expect(subject).to create_concat__fragment('default-myproxy-proxy')
.with_target('15-default-80.conf')
Expand All @@ -51,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 6ef5fbf

Please sign in to comment.