Skip to content

Commit 264f928

Browse files
authored
bring back logic for workers to inherit php_server parent environment (#1956)
* bring back logic to inherit php_server parent environment * change order to account for php { worker file.php 1 { } } cases * suggestion * add inherit env test
1 parent b49aed1 commit 264f928

3 files changed

Lines changed: 24 additions & 3 deletions

File tree

caddy/caddy_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,28 @@ func TestGlobalAndModuleWorker(t *testing.T) {
168168
wg.Wait()
169169
}
170170

171+
func TestModuleWorkerInheritsEnv(t *testing.T) {
172+
tester := caddytest.NewTester(t)
173+
tester.InitServer(`
174+
{
175+
skip_install_trust
176+
admin localhost:2999
177+
}
178+
179+
http://localhost:`+testPort+` {
180+
route {
181+
php {
182+
root ../testdata
183+
env APP_ENV inherit_this
184+
worker worker-with-env.php
185+
}
186+
}
187+
}
188+
`, "caddyfile")
189+
190+
tester.AssertGetResponse("http://localhost:"+testPort+"/worker-with-env.php", http.StatusOK, "Worker has APP_ENV=inherit_this")
191+
}
192+
171193
func TestNamedModuleWorkers(t *testing.T) {
172194
var wg sync.WaitGroup
173195
testPortNum, _ := strconv.Atoi(testPort)

caddy/module.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,6 @@ func (f *FrankenPHPModule) ServeHTTP(w http.ResponseWriter, r *http.Request, _ c
202202

203203
// UnmarshalCaddyfile implements caddyfile.Unmarshaler.
204204
func (f *FrankenPHPModule) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
205-
// First pass: Parse all directives except "worker"
206205
for d.Next() {
207206
for d.NextBlock(0) {
208207
switch d.Val() {

caddy/workerconfig.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ func parseWorkerConfig(d *caddyfile.Dispenser) (workerConfig, error) {
139139
return wc, nil
140140
}
141141

142-
func (wc workerConfig) inheritEnv(env map[string]string) {
142+
func (wc *workerConfig) inheritEnv(env map[string]string) {
143143
if wc.Env == nil {
144144
wc.Env = make(map[string]string, len(env))
145145
}
@@ -151,7 +151,7 @@ func (wc workerConfig) inheritEnv(env map[string]string) {
151151
}
152152
}
153153

154-
func (wc workerConfig) matchesPath(r *http.Request, documentRoot string) bool {
154+
func (wc *workerConfig) matchesPath(r *http.Request, documentRoot string) bool {
155155

156156
// try to match against a pattern if one is assigned
157157
if len(wc.MatchPath) != 0 {

0 commit comments

Comments
 (0)