elixir-lang/plug — pull request #134 by whatyouhide (2014-12-04 11:21:24+00:00)
Title: Add a `Plug.Conn.put_resp_body/2` function

As far as I understand (I'm not 100% sure), what a connection needs in order to be `:set` is a **status code** and a **response body**. This is why `Plug.Conn.resp/3` changes the state of the connection to `:set` but, for example, `put_status/2` alone doesn't.

I added a `put_resp_body/2` function to be consistent with `put_status/2` and also modified the behavior of `put_status/2` so that now both `put_status/2` and `put_resp_body/2` check for the response body and the status respectively: if one is set, than setting the "other" one also turns the state of the connection to `:set`.

This way, these are all equivalents:

``` elixir
conn |> resp(200, "foo")
conn |> put_resp_body("foo") |> put_status(200)
conn |> put_status(200) |> put_resp_body("foo")
```

I think this could also lead to a rewrite of `resp/3` using `put_status/2` and `put_resp_body/2`, so that checks on the body and the status are performed by these two functions (more modular, separated concerns).