vicanso / pingap

A reverse proxy like nginx, built on pingora, simple and efficient.
http://pingap.io/pingap-zh/
Apache License 2.0
315 stars 19 forks source link

host name validation failed when setting host in location conf. #10

Closed WENPIN1 closed 5 months ago

WENPIN1 commented 5 months ago

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
vicanso commented 5 months ago

I will fixed it asap.

vicanso commented 5 months ago

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

Host: localhost:6188

WENPIN1 commented 5 months ago

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

vicanso commented 5 months ago

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.