-
-
Notifications
You must be signed in to change notification settings - Fork 12.5k
/
httpd.rb
183 lines (160 loc) · 6.66 KB
/
httpd.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
class Httpd < Formula
desc "Apache HTTP server"
homepage "https://httpd.apache.org/"
url "https://dlcdn.apache.org/httpd/httpd-2.4.62.tar.bz2"
mirror "https://downloads.apache.org/httpd/httpd-2.4.62.tar.bz2"
sha256 "674188e7bf44ced82da8db522da946849e22080d73d16c93f7f4df89e25729ec"
license "Apache-2.0"
bottle do
sha256 arm64_sequoia: "d88e0c77616130710928d131e06659d58b241252cf53068b75d75a54df3d8ab3"
sha256 arm64_sonoma: "e07d024239ee944db52ecebb1997c75e15144b343b347788b36dce01803bd7c0"
sha256 arm64_ventura: "d497edfd46070f9f4552a5535901700cd20f885b48f2a45aa8550ad50b1f7ecc"
sha256 arm64_monterey: "f830c872c460dfe78c2a95ac3c21a2e0f432fa7f3e4dadacc0d1026e17d11c8a"
sha256 sonoma: "f487133a012b379bfebc45bc90167a27c47e2a2985623b76f336ccb987638e87"
sha256 ventura: "c3069f33e1bb675a6decd0228263f43a909d0351db6059d70bad2778bc83d36b"
sha256 monterey: "ae984f66ee0b60b8955b6e9720ee7733226248f0bb052d195d9f67dc05b61641"
sha256 x86_64_linux: "5a26f97286ecca3915f6a93910f0c624859205eb27f32756867b03708d98212b"
end
depends_on "apr"
depends_on "apr-util"
depends_on "brotli"
depends_on "libnghttp2"
depends_on "openssl@3"
depends_on "pcre2"
uses_from_macos "libxcrypt"
uses_from_macos "libxml2"
uses_from_macos "zlib"
def install
# fixup prefix references in favour of opt_prefix references
inreplace "Makefile.in",
'#@@ServerRoot@@#$(prefix)#', "\#@@ServerRoot@@##{opt_prefix}#"
inreplace "docs/conf/extra/httpd-autoindex.conf.in",
"@exp_iconsdir@", "#{opt_pkgshare}/icons"
inreplace "docs/conf/extra/httpd-multilang-errordoc.conf.in",
"@exp_errordir@", "#{opt_pkgshare}/error"
# fix default user/group when running as root
inreplace "docs/conf/httpd.conf.in", /(User|Group) daemon/, "\\1 _www"
# use Slackware-FHS layout as it's closest to what we want.
# these values cannot be passed directly to configure, unfortunately.
inreplace "config.layout" do |s|
s.gsub! "${datadir}/htdocs", "${datadir}"
s.gsub! "${htdocsdir}/manual", "#{pkgshare}/manual"
s.gsub! "${datadir}/error", "#{pkgshare}/error"
s.gsub! "${datadir}/icons", "#{pkgshare}/icons"
end
if OS.mac?
libxml2 = "#{MacOS.sdk_path_if_needed}/usr"
zlib = "#{MacOS.sdk_path_if_needed}/usr"
else
libxml2 = Formula["libxml2"].opt_prefix
zlib = Formula["zlib"].opt_prefix
end
system "./configure", "--enable-layout=Slackware-FHS",
"--prefix=#{prefix}",
"--sbindir=#{bin}",
"--mandir=#{man}",
"--sysconfdir=#{etc}/httpd",
"--datadir=#{var}/www",
"--localstatedir=#{var}",
"--enable-mpms-shared=all",
"--enable-mods-shared=all",
"--enable-authnz-fcgi",
"--enable-cgi",
"--enable-pie",
"--enable-suexec",
"--with-suexec-bin=#{opt_bin}/suexec",
"--with-suexec-caller=_www",
"--with-port=8080",
"--with-sslport=8443",
"--with-apr=#{Formula["apr"].opt_prefix}",
"--with-apr-util=#{Formula["apr-util"].opt_prefix}",
"--with-brotli=#{Formula["brotli"].opt_prefix}",
"--with-libxml2=#{libxml2}",
"--with-mpm=prefork",
"--with-nghttp2=#{Formula["libnghttp2"].opt_prefix}",
"--with-ssl=#{Formula["openssl@3"].opt_prefix}",
"--with-pcre=#{Formula["pcre2"].opt_prefix}/bin/pcre2-config",
"--with-z=#{zlib}",
"--disable-lua",
"--disable-luajit"
system "make"
ENV.deparallelize if OS.linux?
system "make", "install"
# suexec does not install without root
bin.install "support/suexec"
# remove non-executable files in bin dir (for brew audit)
rm bin/"envvars"
rm bin/"envvars-std"
# avoid using Cellar paths
inreplace %W[
#{include}/httpd/ap_config_layout.h
#{lib}/httpd/build/config_vars.mk
] do |s|
s.gsub! lib/"httpd/modules", HOMEBREW_PREFIX/"lib/httpd/modules"
end
inreplace %W[
#{bin}/apachectl
#{bin}/apxs
#{include}/httpd/ap_config_auto.h
#{include}/httpd/ap_config_layout.h
#{lib}/httpd/build/config_vars.mk
#{lib}/httpd/build/config.nice
] do |s|
s.gsub! prefix, opt_prefix
end
inreplace "#{lib}/httpd/build/config_vars.mk" do |s|
pcre = Formula["pcre2"]
s.gsub! pcre.prefix.realpath, pcre.opt_prefix
s.gsub! "${prefix}/lib/httpd/modules", HOMEBREW_PREFIX/"lib/httpd/modules"
s.gsub! Superenv.shims_path, HOMEBREW_PREFIX/"bin"
end
end
def post_install
(var/"cache/httpd").mkpath
(var/"www").mkpath
end
def caveats
<<~EOS
DocumentRoot is #{var}/www.
The default ports have been set in #{etc}/httpd/httpd.conf to 8080 and in
#{etc}/httpd/extra/httpd-ssl.conf to 8443 so that httpd can run without sudo.
EOS
end
service do
run [opt_bin/"httpd", "-D", "FOREGROUND"]
environment_variables PATH: std_service_path_env
run_type :immediate
end
test do
# Ensure modules depending on zlib and xml2 have been compiled
assert_predicate lib/"httpd/modules/mod_deflate.so", :exist?
assert_predicate lib/"httpd/modules/mod_proxy_html.so", :exist?
assert_predicate lib/"httpd/modules/mod_xml2enc.so", :exist?
begin
port = free_port
expected_output = "Hello world!"
(testpath/"index.html").write expected_output
(testpath/"httpd.conf").write <<~EOS
Listen #{port}
ServerName localhost:#{port}
DocumentRoot "#{testpath}"
ErrorLog "#{testpath}/httpd-error.log"
PidFile "#{testpath}/httpd.pid"
LoadModule authz_core_module #{lib}/httpd/modules/mod_authz_core.so
LoadModule unixd_module #{lib}/httpd/modules/mod_unixd.so
LoadModule dir_module #{lib}/httpd/modules/mod_dir.so
LoadModule mpm_prefork_module #{lib}/httpd/modules/mod_mpm_prefork.so
EOS
pid = fork do
exec bin/"httpd", "-X", "-f", "#{testpath}/httpd.conf"
end
sleep 3
assert_match expected_output, shell_output("curl -s 127.0.0.1:#{port}")
# Check that `apxs` can find `apu-1-config`.
system bin/"apxs", "-q", "APU_CONFIG"
ensure
Process.kill("TERM", pid)
Process.wait(pid)
end
end
end