aboutsummaryrefslogtreecommitdiffstats
path: root/gitolfs3-server/src
diff options
context:
space:
mode:
Diffstat (limited to 'gitolfs3-server/src')
-rw-r--r--gitolfs3-server/src/api.rs5
-rw-r--r--gitolfs3-server/src/handler.rs61
2 files changed, 34 insertions, 32 deletions
diff --git a/gitolfs3-server/src/api.rs b/gitolfs3-server/src/api.rs
index e1a2983..87c1856 100644
--- a/gitolfs3-server/src/api.rs
+++ b/gitolfs3-server/src/api.rs
@@ -19,7 +19,10 @@ pub struct GitLfsErrorData<'a> {
19 pub message: &'a str, 19 pub message: &'a str,
20} 20}
21 21
22pub const fn make_error_resp(code: http::StatusCode, message: &str) -> GitLfsErrorResponse { 22pub const fn make_error_resp<'a>(
23 code: http::StatusCode,
24 message: &'a str,
25) -> GitLfsErrorResponse<'a> {
23 (code, GitLfsJson(Json(GitLfsErrorData { message }))) 26 (code, GitLfsJson(Json(GitLfsErrorData { message })))
24} 27}
25 28
diff --git a/gitolfs3-server/src/handler.rs b/gitolfs3-server/src/handler.rs
index be39721..c5d4a61 100644
--- a/gitolfs3-server/src/handler.rs
+++ b/gitolfs3-server/src/handler.rs
@@ -144,31 +144,31 @@ async fn handle_download_object(
144 }; 144 };
145 } 145 }
146 146
147 if let Some(content_length) = content_length { 147 if let Some(content_length) = content_length
148 if content_length > 0 { 148 && content_length > 0
149 match state 149 {
150 .dl_limiter 150 match state
151 .lock() 151 .dl_limiter
152 .await 152 .lock()
153 .request(content_length as u64) 153 .await
154 .await 154 .request(content_length as u64)
155 { 155 .await
156 Ok(true) => {} 156 {
157 Ok(false) => { 157 Ok(true) => {}
158 return BatchResponseObject::error( 158 Ok(false) => {
159 obj, 159 return BatchResponseObject::error(
160 http::StatusCode::SERVICE_UNAVAILABLE, 160 obj,
161 "Public LFS downloads temporarily unavailable".to_string(), 161 http::StatusCode::SERVICE_UNAVAILABLE,
162 ); 162 "Public LFS downloads temporarily unavailable".to_string(),
163 } 163 );
164 Err(e) => { 164 }
165 println!("Failed to request {content_length} bytes from download limiter: {e}"); 165 Err(e) => {
166 return BatchResponseObject::error( 166 println!("Failed to request {content_length} bytes from download limiter: {e}");
167 obj, 167 return BatchResponseObject::error(
168 http::StatusCode::INTERNAL_SERVER_ERROR, 168 obj,
169 "Internal server error".to_string(), 169 http::StatusCode::INTERNAL_SERVER_ERROR,
170 ); 170 "Internal server error".to_string(),
171 } 171 );
172 } 172 }
173 } 173 }
174 } 174 }
@@ -433,12 +433,11 @@ fn s3_encode_checksum(oid: Oid) -> String {
433} 433}
434 434
435fn s3_validate_checksum(oid: Oid, obj: &HeadObjectOutput) -> bool { 435fn s3_validate_checksum(oid: Oid, obj: &HeadObjectOutput) -> bool {
436 if let Some(checksum) = obj.checksum_sha256() { 436 if let Some(checksum) = obj.checksum_sha256()
437 if let Ok(checksum) = BASE64_STANDARD.decode(checksum) { 437 && let Ok(checksum) = BASE64_STANDARD.decode(checksum)
438 if let Ok(checksum32b) = TryInto::<[u8; 32]>::try_into(checksum) { 438 && let Ok(checksum32b) = TryInto::<[u8; 32]>::try_into(checksum)
439 return Oid::from(checksum32b) == oid; 439 {
440 } 440 return Oid::from(checksum32b) == oid;
441 }
442 } 441 }
443 true 442 true
444} 443}