cloudflare / pingora

A library for building fast, reliable and evolvable network services.
Apache License 2.0
20.21k stars 1.1k forks source link

Error "Prematurely before response header is sent" when using netcat to send http request #305

Open CodyPubNub opened 5 days ago

CodyPubNub commented 5 days ago

Describe the bug

This error is being returned instead of successfully reverse proxying when using netcat instead of curl

Pingora info

Latest commit on main, using pingora-proxy/examples/load_balancer.rs example

Steps to reproduce

# run load balancer example of the pingora-proxy
cargo run --example load_balancer

# send http request using netcat
echo -e "GET / HTTP/1.1\r\nHost: one.one.one.one\r\n\r\n" | nc 127.0.0.1 6188

Expected results

This very same netcat command works when sending requests to nginx. I was hoping Pingora would do the same.

curl http://127.0.0.1:6188 -v -H 'host: one.one.one.one'
*   Trying 127.0.0.1:6188...
* Connected to 127.0.0.1 (127.0.0.1) port 6188
> GET / HTTP/1.1
> Host: one.one.one.one
> User-Agent: curl/8.6.0
> Accept: */*
>
< HTTP/1.1 200 OK

Observed results

No response received, and pingora encounters an error while proxying:

[2024-06-24T22:55:46Z ERROR pingora_proxy] Fail to proxy: Downstream ConnectionClosed context: Peer: addr: 1.1.1.1:443, scheme: HTTPS,sni: one.one.one.one, cause:  context: Prematurely before response header is sent, status: 0, tries: 1, retry: false, GET /, Host: one.one.one.one

Additional context

I've attached tcpdump of both curl and netcat during this testing tcpdump_curl.txt tcpdump_netcat.txt

eaufavor commented 4 days ago

Related discussion https://github.com/httpwg/http-core/issues/22