MCPcopy
hub / github.com/caddyserver/caddy / parsePHPFastCGI

Function parsePHPFastCGI

modules/caddyhttp/reverseproxy/fastcgi/caddyfile.go:172–442  ·  view source on GitHub ↗

parsePHPFastCGI parses the php_fastcgi directive, which has the same syntax as the reverse_proxy directive (in fact, the reverse_proxy's directive Unmarshaler is invoked by this function) but the resulting proxy is specially configured for most™️ PHP apps over FastCGI. A line such as this: php_fas

(h httpcaddyfile.Helper)

Source from the content-addressed store, hash-verified

170// user's matcher as a prerequisite to enter the subroute. In other
171// words, the directive's matcher is necessary, but not sufficient.
172func parsePHPFastCGI(h httpcaddyfile.Helper) ([]httpcaddyfile.ConfigValue, error) {
173 if !h.Next() {
174 return nil, h.ArgErr()
175 }
176
177 // set up the transport for FastCGI, and specifically PHP
178 fcgiTransport := Transport{}
179
180 // set up the set of file extensions allowed to execute PHP code
181 extensions := []string{".php"}
182
183 // set the default index file for the try_files rewrites
184 indexFile := "index.php"
185
186 // set up for explicitly overriding try_files
187 var tryFiles []string
188
189 // if the user specified a matcher token, use that
190 // matcher in a route that wraps both of our routes;
191 // either way, strip the matcher token and pass
192 // the remaining tokens to the unmarshaler so that
193 // we can gain the rest of the reverse_proxy syntax
194 userMatcherSet, err := h.ExtractMatcherSet()
195 if err != nil {
196 return nil, err
197 }
198
199 // make a new dispenser from the remaining tokens so that we
200 // can reset the dispenser back to this point for the
201 // reverse_proxy unmarshaler to read from it as well
202 dispenser := h.NewFromNextSegment()
203
204 // read the subdirectives that we allow as overrides to
205 // the php_fastcgi shortcut
206 // NOTE: we delete the tokens as we go so that the reverse_proxy
207 // unmarshal doesn't see these subdirectives which it cannot handle
208 for dispenser.Next() {
209 for dispenser.NextBlock(0) {
210 // ignore any sub-subdirectives that might
211 // have the same name somewhere within
212 // the reverse_proxy passthrough tokens
213 if dispenser.Nesting() != 1 {
214 continue
215 }
216
217 // parse the php_fastcgi subdirectives
218 switch dispenser.Val() {
219 case "root":
220 if !dispenser.NextArg() {
221 return nil, dispenser.ArgErr()
222 }
223 fcgiTransport.Root = dispenser.Val()
224 dispenser.DeleteN(2)
225
226 case "split":
227 extensions = dispenser.RemainingArgs()
228 dispenser.DeleteN(len(extensions) + 1)
229 if len(extensions) == 0 {

Callers

nothing calls this directly

Calls 15

UnmarshalCaddyfileMethod · 0.95
WeakStringTypeAlias · 0.92
JSONModuleObjectFunction · 0.92
ArgErrMethod · 0.80
ExtractMatcherSetMethod · 0.80
NewFromNextSegmentMethod · 0.80
NextBlockMethod · 0.80
NestingMethod · 0.80
ValMethod · 0.80
NextArgMethod · 0.80
DeleteNMethod · 0.80

Tested by

no test coverage detected