-
Notifications
You must be signed in to change notification settings - Fork 125
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
Add examples about how to use status_mut()
to change the status code of a response
#604
Comments
status_mut()
to change the status code of a response
The |
It looks good, and what do you think about including it in the middleware examples? I meant, it's a common case and at the first is not clear how to do it |
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: