Skip to content
Snippets Groups Projects
Commit 4846d822 authored by DeathwingTheBoss's avatar DeathwingTheBoss
Browse files

- Improve unwrap survival

- Ignore content-type header (jussi-like)
- Version bump
parent 916f30a5
No related branches found
No related tags found
No related merge requests found
......@@ -559,7 +559,7 @@ checksum = "0688c2a7f92e427f44895cd63841bff7b29f8d7a1648b9e7e07a4a365b2e1257"
[[package]]
name = "drone"
version = "0.1.2"
version = "0.1.3"
dependencies = [
"actix-web",
"config",
......
[package]
name = "drone"
version = "0.1.2"
version = "0.1.3"
edition = "2021"
authors = ["Deathwing <hi@deathwing.me>"]
description = "A caching reverse-proxy application for the Hive blockchain."
......
use std::{time::Duration, sync::Mutex};
use actix_web::{web, App, HttpResponse, HttpServer, Responder, HttpRequest};
use actix_web::{web::{self, JsonConfig}, App, HttpResponse, HttpServer, Responder, HttpRequest};
use serde::{Deserialize, Serialize};
use reqwest::{Client, ClientBuilder};
use lru_time_cache::LruCache;
......@@ -90,16 +90,25 @@ async fn api_call(req: HttpRequest, call: web::Json<APICall>, data: web::Data<Ap
// Log the request, if there's Cloudflare header (CF-Connecting-IP) use that instead of peer_addr.
let get_cloudflare_ip = req.headers().get("CF-Connecting-IP");
let client_ip = match get_cloudflare_ip {
Some(ip) => ip.to_str().unwrap().to_string(),
None => req.peer_addr().unwrap().ip().to_string(),
};
Some(ip) => ip.to_str().map(|ip| ip.to_string()),
None => Ok(req.peer_addr().unwrap().ip().to_string()),
};
let client_ip = match client_ip {
Ok(ip) => ip,
Err(_) => return HttpResponse::InternalServerError().json(ErrorStructure {
code: 9999,
message: "Internal Server Error".to_string(),
error_data: "Invalid Cloudflare Proxy Header.".to_string(),
}),
};
let formatted_log =
format!(
"Timestamp: {} || IP: {} || HTTP Version: {:?} || Request Method: {} || Request Params: {}",
"Timestamp: {} || IP: {} || Request Method: {} || Request Params: {}",
human_timestamp,
client_ip,
req.version(),
json_rpc_call.method,
json_rpc_call.params,
);
......@@ -258,6 +267,7 @@ async fn main() -> std::io::Result<()> {
HttpServer::new(move || {
App::new()
.app_data(_cache.clone())
.app_data(JsonConfig::default().content_type_required(false))
.route("/", web::get().to(index))
.route("/", web::post().to(api_call))
.route("/health", web::get().to(index))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment