seanmonstar / warp

A super-easy, composable, web server framework for warp speeds.
https://seanmonstar.com/post/176530511587/warp
MIT License
9.58k stars 720 forks source link

add proxy-server example #354

Open blittable opened 4 years ago

blittable commented 4 years ago

Our use-case is ci/cd deployment with a non-privileged on ubuntu where the lower port ranges are restricted and can be handled with a proxy server. There may be others.

I've peeked at the hyper example: https://github.com/hyperium/hyper/blob/master/examples/http_proxy.rs and would be happy to contribute with some suggestions/guidance.

Related issue: #230

seanmonstar commented 4 years ago

A naive proxy example could be a good idea! Though, there isn't currently a way to get the on_upgrade in warp to allow for tunneling.

cheako commented 4 years ago

Looking at this it looks like this is about a Request/Response combination that results in a usable Socket afterwards? I must say the documentation isn't exactly verbose.

I'm looking to do Cut-through switching. That is I want to validate and alter Request Headers and then hand off the Body to another HTTPD without storing the body(could be several GB of file upload). I likewise want to do the same with the Response, for file downloads.

The whole story. I recently wanted to share a saved game file but I was unable to locate a file sharing service that I was happy with. I've obtained a VPS from Google, but it has limited storage. I plan to use FreeNet as my file storage backend. What I'm looking to do is pass through filtered access to an instance of FreeNet.

Can Warp do anything like this?

Edit: Similar to #175

drakedevel commented 4 years ago

The code for warp::filters::ws could in principle be adapted into a HTTP CONNECT proxy (like the linked hyper example), but it relies on the body filter (which is private) to get access to the underlying hyper structs. So I think implementing that example in warp is actually impossible right now without changes to the library.

@seanmonstar warp seems to be careful about keeping the raw Body hidden, so I assume you want to keep it that way (so exposing the body filter wouldn't be an option). What would you think about an upgrade filter that exposes a hyper::upgrade::Upgraded? The ws filter should be able to reuse it, and the downcast function on that can get you all the way back to a raw tokio TcpStream for @cheako 's use-case (as well as my own).