Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Client hangs on redirector plug app #40

Closed
rhruiz opened this issue Nov 2, 2022 · 2 comments
Closed

Client hangs on redirector plug app #40

rhruiz opened this issue Nov 2, 2022 · 2 comments

Comments

@rhruiz
Copy link

rhruiz commented Nov 2, 2022

Hello,

I was testing porting an app from cowboy2 to bandit and found a behaviour I am not sure on where it should be fixed.

My app is using Plug.Router (no phoenix) and one of the endpoints makes a 301 redirect, with a location header and an empty body.

A simple simulation of that can be:

  match _ do
    conn
    |> put_resp_header("location", "http://example.com")
    |> send_resp(301, "")
  end

Clients hang waiting for some indication that content is done, as in:

> curl -v http://localhost:4000/
# ...
< HTTP/1.1 301 Moved Permanently
< date: Wed, 02 Nov 2022 14:46:38 GMT
< cache-control: max-age=0, private, must-revalidate
< x-request-id: FyPL1BNQtEYMFM4AAQsD
< location: http://example.org/
* no chunk, no close, no size. Assume close to signal end

I figured it out that cowboy adds a content-length: 0 header making curl and other clients happy.

I fixed in my app by doing the same with a put_resp_header call. My question is: who should handle that case? Is my plug required to provide the content-length?

@mtrudel
Copy link
Owner

mtrudel commented Nov 2, 2022

Thanks for the report!

As it turns out Bandit wasn't strict enough in its HTTP/1.x content-length return value logic. This is fixed on main at d25735b and will be tagged for release as 0.5.8 as soon as CI passes.

@mtrudel
Copy link
Owner

mtrudel commented Nov 2, 2022

Released as 0.5.8

Thanks again for the report!

@mtrudel mtrudel closed this as completed Nov 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants