Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle scheme-less upstreams properly #9

Merged
merged 1 commit into from
Apr 1, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions processors.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,17 @@ func processFastCGIPass(dirs []Directive) (*caddyhttp.Subroute, []caddyconfig.Wa
TransportRaw: caddyconfig.JSONModuleObject(fcgiTransport, "protocol", "fastcgi", nil),
}

/***
* If upstream doesn't have scheme explicitly specified as scheme://host, then
* assume it's tcp by prefixing it with tcp://. Later we check if the hostname is `unix:`.
* If so, then the arguemnt of fastcgi_pass was of the form `unix:/some/path`.
**/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious, why the block style comment here? 🤔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Laziness 😂 didn't feel like double tapping the forward slash key

passDirective, _ := getDirective(dirs, "fastcgi_pass")
upstream, err := url.Parse(passDirective.Param(1))
passArgs := passDirective.Param(1)
if !strings.Contains(passArgs, "://") {
passArgs = "tcp://" + passArgs
}
upstream, err := url.Parse(passArgs)
if err != nil {
warns = append(warns, caddyconfig.Warning{
File: passDirective.File,
Expand All @@ -272,9 +281,12 @@ func processFastCGIPass(dirs []Directive) (*caddyhttp.Subroute, []caddyconfig.Wa
})
return nil, warns
}
network := "tcp"
host := upstream.Hostname()
if upstream.Hostname() == unixPrefix {

var network, host string = upstream.Scheme, upstream.Hostname()

// the argument of fastcgi_pass could have been of either of these forms:
// http://unix:/tmp/backend.socket:/uri/ , unix:///some/path
if upstream.Hostname() == unixPrefix || upstream.Scheme == "unix" {
network = "unix"
host = (strings.Split(upstream.Path, ":"))[0]
}
Expand Down