diff options
author | Rutger Broekhoff | 2024-01-24 17:09:53 +0100 |
---|---|---|
committer | Rutger Broekhoff | 2024-01-24 17:09:53 +0100 |
commit | 7c75eccd5e2bbf453aa043ca3627b4596b8b738a (patch) | |
tree | 185737084c9cf1b5692a51246f5723e06f7bdadf /rs | |
parent | 35c6a80e95ca3d29749203c601182f07f80d19a7 (diff) | |
download | gitolfs3-7c75eccd5e2bbf453aa043ca3627b4596b8b738a.tar.gz gitolfs3-7c75eccd5e2bbf453aa043ca3627b4596b8b738a.zip |
Properly propagate JSON parsing error
Diffstat (limited to 'rs')
-rw-r--r-- | rs/server/src/main.rs | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/rs/server/src/main.rs b/rs/server/src/main.rs index 7060b15..b8428cb 100644 --- a/rs/server/src/main.rs +++ b/rs/server/src/main.rs | |||
@@ -287,11 +287,14 @@ enum GitLfsJsonRejection { | |||
287 | 287 | ||
288 | impl IntoResponse for GitLfsJsonRejection { | 288 | impl IntoResponse for GitLfsJsonRejection { |
289 | fn into_response(self) -> Response { | 289 | fn into_response(self) -> Response { |
290 | make_error_resp( | 290 | match self { |
291 | StatusCode::UNSUPPORTED_MEDIA_TYPE, | 291 | Self::Json(rej) => rej.into_response(), |
292 | &format!("Expected request with `Content-Type: {LFS_MIME}`"), | 292 | Self::MissingGitLfsJsonContentType => make_error_resp( |
293 | ) | 293 | StatusCode::UNSUPPORTED_MEDIA_TYPE, |
294 | .into_response() | 294 | &format!("Expected request with `Content-Type: {LFS_MIME}`"), |
295 | ) | ||
296 | .into_response(), | ||
297 | } | ||
295 | } | 298 | } |
296 | } | 299 | } |
297 | 300 | ||
@@ -944,3 +947,19 @@ async fn obj_download( | |||
944 | 947 | ||
945 | (headers, body).into_response() | 948 | (headers, body).into_response() |
946 | } | 949 | } |
950 | |||
951 | #[test] | ||
952 | fn test_mimetype() { | ||
953 | assert!(is_git_lfs_json_mimetype("application/vnd.git-lfs+json")); | ||
954 | assert!(!is_git_lfs_json_mimetype("application/vnd.git-lfs")); | ||
955 | assert!(!is_git_lfs_json_mimetype("application/json")); | ||
956 | assert!(is_git_lfs_json_mimetype( | ||
957 | "application/vnd.git-lfs+json; charset=utf-8" | ||
958 | )); | ||
959 | assert!(is_git_lfs_json_mimetype( | ||
960 | "application/vnd.git-lfs+json; charset=UTF-8" | ||
961 | )); | ||
962 | assert!(!is_git_lfs_json_mimetype( | ||
963 | "application/vnd.git-lfs+json; charset=ISO-8859-1" | ||
964 | )); | ||
965 | } | ||