pingora icon indicating copy to clipboard operation
pingora copied to clipboard

Unclear how to get request host

Open stepancheg opened this issue 4 months ago • 2 comments

What is the problem your feature solves, or the need it fulfills?

This is code I have

    async fn upstream_peer(
        &self,
        session: &mut Session,
        _ctx: &mut Self::CTX,
    ) -> pingora::Result<Box<HttpPeer>> {
        let Some(host) = session.req_header().uri.host() else {
            return Err(pingora::Error::new_str("host unset"));
        };

it reports host unset. Which is probably expected. But then how do I get host? I guess

session.req_header().headers.get("host")

or

session.req_header().headers.get(":authority")

or both?

Describe the solution you'd like

Add a function like

RequestHeader::host(&self) -> &str

Describe alternatives you've considered

Continue reading sources.

Additional context

0.5.0

stepancheg avatar Aug 12 '25 22:08 stepancheg

@stepancheg Hi, According to this docs, it can be got the host header following that. Can you try this?

session.req_header().headers().get(http::header::HOST)

u5surf avatar Sep 29 '25 06:09 u5surf

@u5surf even that doc does not mention that http::header::HOST will returns :authority for HTTP/2.

stepancheg avatar Sep 29 '25 10:09 stepancheg