cloudflare / pingora

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

Support of SCGI protocol and connect upstream via unix domain socket file #171

Open KunjeshBaghel opened 3 months ago

KunjeshBaghel commented 3 months ago

Hi, Pingora dev community,

My upstream supports only SCGI protocol. I am building a reverse proxy, which will receive HTTP Post requests and translate HTTP to SCGI protocol. Also, it will communicate upstream using the Unix domain socket file. It will receive the response in SCGI protocol, convert it back to HTTP, and respond to the client.

I am not able to achieve this workflow. Could you please suggest whether it is supported in Pingora and how easy or hard it is to achieve this setup with a plugin customer code in Pingor's workflow execution?

If possible, please point me to some example code where we change the communication protocol for upstream.

Thanks.

andrewhavck commented 3 months ago

We don't officially support SCGI, you create a UDS upstream HttpPeer with the new_uds function.

KunjeshBaghel commented 3 months ago

Thanks for the quick replay.

I will have a custom code that will do HTTP to SCGI conversion. But the question here is, will I be able to customize Pingora's workflow so that it sends the converted SCGI protocol upstream, not the HTTP request?

palant commented 2 months ago

But the question here is, will I be able to customize Pingora's workflow so that it sends the converted SCGI protocol upstream, not the HTTP request?

That does not appear to be the case currently. The proxying functionality assumes an HTTP backend and will always send an HTTP request to it. There is no way of overriding this behavior, short of implementing the entire functionality as a request filter (thus duplicating lots of code).

IMHO this needs to be improved. While Pingora doesn’t necessarily have to support non-HTTP peers itself, it should allow them to be implemented.

glebpinigin commented 2 months ago

Documentation for LoadBalancer may be incorrect in that case. In this page there is a following explanation:

Note: ToSocketAddrs will invoke blocking network IO for DNS lookup if the input cannot be directly parsed as SocketAddr.

And SocketAddr is a link to pingora's enum that supports unix sockets. However in fact ToSocketAddr trait creates SocketAddr enum from std, which does not support unix sockets.

It all gets a little confusing when you try to understand which sockets the load balancer does and doesn't support.