aboutsummaryrefslogtreecommitdiffstats
path: root/rs/server/src
diff options
context:
space:
mode:
Diffstat (limited to 'rs/server/src')
-rw-r--r--rs/server/src/main.rs36
1 files changed, 32 insertions, 4 deletions
diff --git a/rs/server/src/main.rs b/rs/server/src/main.rs
index cbac138..a8c6aa5 100644
--- a/rs/server/src/main.rs
+++ b/rs/server/src/main.rs
@@ -236,12 +236,16 @@ async fn main() -> ExitCode {
236enum TransferAdapter { 236enum TransferAdapter {
237 #[serde(rename = "basic")] 237 #[serde(rename = "basic")]
238 Basic, 238 Basic,
239 #[serde(other)]
240 Unknown,
239} 241}
240 242
241#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone, Copy)] 243#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone, Copy)]
242enum HashAlgo { 244enum HashAlgo {
243 #[serde(rename = "sha256")] 245 #[serde(rename = "sha256")]
244 Sha256, 246 Sha256,
247 #[serde(other)]
248 Unknown,
245} 249}
246 250
247impl Default for HashAlgo { 251impl Default for HashAlgo {
@@ -250,7 +254,7 @@ impl Default for HashAlgo {
250 } 254 }
251} 255}
252 256
253#[derive(Debug, Deserialize, Clone)] 257#[derive(Debug, Deserialize, PartialEq, Eq, Clone)]
254struct BatchRequestObject { 258struct BatchRequestObject {
255 oid: common::Oid, 259 oid: common::Oid,
256 size: i64, 260 size: i64,
@@ -265,7 +269,7 @@ fn default_transfers() -> Vec<TransferAdapter> {
265 vec![TransferAdapter::Basic] 269 vec![TransferAdapter::Basic]
266} 270}
267 271
268#[derive(Deserialize)] 272#[derive(Debug, Deserialize, PartialEq, Eq, Clone)]
269struct BatchRequest { 273struct BatchRequest {
270 operation: common::Operation, 274 operation: common::Operation,
271 #[serde(default = "default_transfers")] 275 #[serde(default = "default_transfers")]
@@ -344,11 +348,10 @@ where
344{ 348{
345 type Rejection = GitLfsJsonRejection; 349 type Rejection = GitLfsJsonRejection;
346 350
347 async fn from_request(mut req: Request, state: &S) -> Result<Self, Self::Rejection> { 351 async fn from_request(req: Request, state: &S) -> Result<Self, Self::Rejection> {
348 if !has_git_lfs_json_content_type(&req) { 352 if !has_git_lfs_json_content_type(&req) {
349 return Err(GitLfsJsonRejection::MissingGitLfsJsonContentType); 353 return Err(GitLfsJsonRejection::MissingGitLfsJsonContentType);
350 } 354 }
351 req.headers_mut().insert(header::CONTENT_TYPE, HeaderValue::from_static("application/json"));
352 Json::<T>::from_request(req, state) 355 Json::<T>::from_request(req, state)
353 .await 356 .await
354 .map(GitLfsJson) 357 .map(GitLfsJson)
@@ -964,3 +967,28 @@ fn test_mimetype() {
964 "application/vnd.git-lfs+json; charset=ISO-8859-1" 967 "application/vnd.git-lfs+json; charset=ISO-8859-1"
965 )); 968 ));
966} 969}
970
971#[test]
972fn test_deserialize() {
973 let json = r#"{"operation":"upload","objects":[{"oid":"8f4123f9a7181f488c5e111d82cefd992e461ae5df01fd2254399e6e670b2d3c","size":170904}],
974 "transfers":["lfs-standalone-file","basic","ssh"],"ref":{"name":"refs/heads/main"},"hash_algo":"sha256"}"#;
975 let expected = BatchRequest {
976 operation: common::Operation::Upload,
977 objects: vec![BatchRequestObject {
978 oid: "8f4123f9a7181f488c5e111d82cefd992e461ae5df01fd2254399e6e670b2d3c"
979 .parse()
980 .unwrap(),
981 size: 170904,
982 }],
983 transfers: vec![
984 TransferAdapter::Unknown,
985 TransferAdapter::Basic,
986 TransferAdapter::Unknown,
987 ],
988 hash_algo: HashAlgo::Sha256,
989 };
990 assert_eq!(
991 serde_json::from_str::<BatchRequest>(json).unwrap(),
992 expected
993 );
994}