cloudflare/pingora

Unclear how to get request host

Opened this issue · 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
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 even that doc does not mention that http::header::HOST will returns :authority for HTTP/2.