Treat both 2XX and 3XX responses as successful.#14
Merged
connec merged 1 commit intodigital-society-coop:masterfrom Feb 8, 2023
Merged
Treat both 2XX and 3XX responses as successful.#14connec merged 1 commit intodigital-society-coop:masterfrom
connec merged 1 commit intodigital-society-coop:masterfrom
Conversation
greizgh
reviewed
Dec 3, 2022
Contributor
greizgh
left a comment
There was a problem hiding this comment.
You could also add a test case checking for commit on redirection:
#[tokio::test]
async fn commit_on_redirection() {
let (_db, pool, response) = build_app(|mut tx: Tx| async move {
let (_, _) = insert_user(&mut tx, 1, "john redirect").await;
http::StatusCode::SEE_OTHER
})
.await;
assert!(response.status.is_redirection());
let users: Vec<(i32, String)> = sqlx::query_as("SELECT * FROM users")
.fetch_all(&pool)
.await
.unwrap();
assert_eq!(users, vec![(1, "john redirect".to_string())]);
}
src/layer.rs
Outdated
| let res = res.await.unwrap(); // inner service is infallible | ||
|
|
||
| if res.status().is_success() { | ||
| if res.status().is_success() || res.status().is_redirection() { |
Contributor
There was a problem hiding this comment.
It might be safer to check that there was no error:
Suggested change
| if res.status().is_success() || res.status().is_redirection() { | |
| if !(res.status().is_server_error() || res.status().is_client_error()) { |
Contributor
Author
|
I've made both your suggested changes. Thanks for taking a look at this. |
Member
|
Thank you both for the PR, apologies for taking so long to get to it. I'll just wait for the workflows to pass then go ahead with a merge. |
connec
previously approved these changes
Feb 8, 2023
The `303 See Other` response is often used to direct clients to another page after successfully creating a new resource, and such behavior is encouraged by web standards.
b6b45d2 to
185fe4c
Compare
connec
approved these changes
Feb 8, 2023
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The
303 See Otherresponse is often used to direct clients to another page after successfully creating a new resource, and such behavior is encouraged by web standards.Thanks for this module, it's very useful. I'm using it to develop a web application.