pingap icon indicating copy to clipboard operation
pingap copied to clipboard

host name validation failed when setting host in location conf.

Open WENPIN1 opened this issue 1 year ago • 2 comments

After setting host in location conf

[locations.lo] upstream = "charts" path = "/" host = "localhost" proxy_set_headers = ["name:value"] proxy_add_headers = ["name:value"] rewrite = "" plugins = ["pingap:requestId", "pingap:stats"],

The result pf curl -v "http://localhost:6188" is incorrect. It seems header.uri.host() didn't work as expected.

*   Trying [::1]:6188...
* connect to ::1 port 6188 failed: Connection refused
*   Trying 127.0.0.1:6188...
* Connected to localhost (127.0.0.1) port 6188
> GET / HTTP/1.1
> Host: localhost:6188

> User-Agent: curl/8.4.0
> Accept: */*
> 
< HTTP/1.1 500 Internal Server Error
< Content-Length: 32
< Cache-Control: private, no-store
< Date: Fri, 24 May 2024 10:05:54 GMT
< Connection: keep-alive
< 
* Connection #0 to host localhost left intact
Location not found, host: path:/
%      
截圖 2024-05-24 18 06 16

WENPIN1 avatar May 24 '24 10:05 WENPIN1

I will fixed it asap.

vicanso avatar May 24 '24 15:05 vicanso

@WENPIN1 Please try the latest version. And the host should be localhost:6188.

Host: localhost:6188

vicanso avatar May 26 '24 03:05 vicanso

Why not split the host:port into host string for the convenience ? https://github.com/vicanso/pingap/blob/main/src/util/mod.rs#L208)

pub fn get_host(header: &RequestHeader) -> Option<&str> {
    if let Some(host) = header.headers.get("Host") {
        return host.to_str().unwrap_or_default().split(':').next();
    }
    header.uri.host()
}

Sorry for your inconvenience !

-WENPIN

WENPIN1 avatar May 27 '24 02:05 WENPIN1

I made a mistake about http host and host. I will look up how other reverse proxies handle it and decide how to adjust it.

vicanso avatar May 27 '24 12:05 vicanso