diff --git a/Cargo.lock b/Cargo.lock index a2a461ab164ad8e71a92150fd35b4c8dfc3ea7f4..69134dff752ba5e1df2d587a5c256a55f4e91a54 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -574,7 +574,7 @@ checksum = "0688c2a7f92e427f44895cd63841bff7b29f8d7a1648b9e7e07a4a365b2e1257" [[package]] name = "drone" -version = "0.1.9" +version = "0.2.0" dependencies = [ "actix-cors", "actix-web", diff --git a/Cargo.toml b/Cargo.toml index a1cefd2ecd30fe00b93cafd7fa68a6af2b073522..71d0c8da5eb394e1c6149b593026463c27cf7dfb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "drone" -version = "0.1.9" +version = "0.2.0" edition = "2021" authors = ["Deathwing <hi@deathwing.me>"] description = "A caching reverse-proxy application for the Hive blockchain." diff --git a/src/main.rs b/src/main.rs index 8a8d749ff31bed4d1640863f6952e3831019aecb..2ff6b2a4bd341df1dc18ac24930116533087217b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -188,7 +188,7 @@ async fn handle_request( Ok(response) => response, Err(err) => { return Err(ErrorStructure { - code: 1000, + code: -32700, message: format!("Unable to send request to endpoint."), error: ErrorField::Message(err.to_string()), }) @@ -198,7 +198,7 @@ async fn handle_request( Ok(text) => text, Err(err) => { return Err(ErrorStructure { - code: 2000, + code: -32600, message: format!("Received an invalid response from the endpoint."), error: ErrorField::Message(err.to_string()), }) @@ -216,7 +216,7 @@ async fn handle_request( }; if json_body["error"].is_object() { return Err(ErrorStructure { - code: 4000, + code: -32602, message: format!("Endpoint returned an error."), error: ErrorField::Object(json_body["error"].clone()), }); @@ -284,6 +284,15 @@ async fn api_call( } APICall::Batch(requests) => { let mut responses = Vec::new(); + // If there's over 100 in the batch, return an error. + if requests.len() > 100 { + return HttpResponse::InternalServerError().json(ErrorStructure { + code: -32600, + message: "Internal Server Error".to_string(), + error: ErrorField::Message("Batch size too large.".to_string()), + }); + } + for request in requests { let result = handle_request(&request, &data, &user_ip).await; match result { @@ -365,7 +374,7 @@ async fn main() -> std::io::Result<()> { .app_data(web::JsonConfig::default() .content_type(|_| true) .content_type_required(false) - .limit(1024)) + .limit(1024 * 100)) // 100kb .app_data(_cache.clone()) .route("/", web::get().to(index)) .route("/", web::post().to(api_call))