Add examples about how to use status_mut()
to change the status code of a response
#604
Labels
status_mut()
to change the status code of a response
#604
The problem
I was looking for a way to change the status code of my response and it has been hard to find to me, I based on the next example to create a CORS middleware, but the response status code was always 200 code, instead of 401 (unauthorized), so I had to change the status code manually, but I don't find any way to change it properly.
gotham/examples/middleware/introduction/src/main.rs
Lines 75 to 92 in 84c7f08
I also tried to base on this documentation to change the status code, but that doesn't work with my problem, since this example instead of modifying an existing response is creating a new empty response.
gotham/examples/middleware/introduction_await/src/main.rs
Lines 100 to 112 in 84c7f08
Then I noticed the
status_mut
function in the response struct, but it doesn't have any documentation about how to use it. So I couldn't use it anyway. Later I checked and found this block of code in this GitHub repository and I based on it to change the response status code, and that worked properly. But I think it could be included in the examples, for example, the first one that I mentioned could include this part about how to change the status codegotham/gotham_derive/src/extenders.rs
Lines 15 to 19 in 7251955
The request
I suggest to add examples about how to use
status_mut()
to the middleware examples or to another example where it was visible so beginners can easily change thestatus_mut
of a responseThe text was updated successfully, but these errors were encountered: