elixir-reverse-proxy icon indicating copy to clipboard operation
elixir-reverse-proxy copied to clipboard

Read body doesn't bring any result if ReverseProxy plug used inside Phoenix

Open tjsousa opened this issue 10 years ago • 3 comments

I have tinkered with integrating the ReverseProxy plug within a Phoenix app - using forward so that just a few selected endpoints would be proxied upstream.

However, I came across an issue where Plug's read_body/2 is being called earlier in the pipeline (inside Phoenix parsers), thus rendering the ReverseProxy call to read the body useless.

Any idea on a way to overcome this issue?

tjsousa avatar Nov 25 '15 22:11 tjsousa

Spent a little time making this work in phoenix. read_body/2 has long since been called in phoenix. They key is to use body_params. Just call Poison.encode!(conn.body_params) rather than calling Conn.read_body(conn). (My actual change is to see if body_params exists and call Poison.encode!/1 if it does otherwise do the current code path using read_body/2.)

baldmountain avatar Aug 02 '17 17:08 baldmountain

@baldmountain Thanks for looking into this! If you're willing, be sure to submit a PR with your changes. I'd love for you to get credit here. If you're unable, I'll definitely be sure to attribute you with the solution.

slogsdon avatar Aug 03 '17 02:08 slogsdon

@slogsdon sure, I can make a PR. I'll have to implement it properly since I just hacked things together to make it work for my case. :)

baldmountain avatar Aug 03 '17 13:08 baldmountain