~zethra/stargazer

3492c0103346a433d7df5aa22d17ce87fe19bcbc — Ben Aaron Goldberg 27 days ago 122e3ac
scgi: scgi-address for unix socket doesn't have to exist on startup

Before, stargazer would treat scgi-address as a Unix domain socket path
if it existed at start up. Now it treats it as a TCP socket path if it's
a valid socket address and a Unix domain socket path otherwise.
1 files changed, 16 insertions(+), 18 deletions(-)

M src/config.rs
M src/config.rs => src/config.rs +16 -18
@@ 167,26 167,24 @@ pub fn load(config_path: impl AsRef<Path>) -> Result<Config> {
                let scgi_addr = props.remove("scgi-address").context(
                    "Routes with `scgi` on must include an `scg-address`",
                )?;
                let unix_addr = Path::new(&scgi_addr);
                if unix_addr.exists() {
                    SCGIRoute {
                        addr: SCGIAddress::Unix(unix_addr.to_owned()),
                        timeout: cgi_timeout,
                    }
                    .into()
                } else {
                    SCGIRoute {
                        addr: SCGIAddress::TCP(
                            scgi_addr
                                .to_socket_addrs()
                                .context("`scgi-address is invalid`")?
                                .next()
                                .context("`scgi-address is invalid`")?,
                        ),
                        timeout: cgi_timeout,
                let mut is_sock = false;
                let mut addr = None;
                if let Ok(mut sock_addr) = scgi_addr.to_socket_addrs() {
                    if let Some(sock_addr) = sock_addr.next() {
                        is_sock = true;
                        addr = Some(SCGIAddress::TCP(sock_addr));
                    }
                    .into()
                }
                if !is_sock {
                    addr = Some(SCGIAddress::Unix(
                        Path::new(&scgi_addr).to_owned(),
                    ));
                }
                SCGIRoute {
                    addr: addr.unwrap(),
                    timeout: cgi_timeout,
                }
                .into()
            } else if redirect.is_some() {
                let permanent = props.remove_yn("permanent");
                RedirectRoute {