From 3d0b00b176f00417738ce2726ce254f5802bf7f3 Mon Sep 17 00:00:00 2001 From: Checksum Date: Sat, 21 Oct 2023 21:34:38 -0500 Subject: [PATCH] fix!: headers cannot have `_` in them. --- benches/upload.rs | 6 +++--- examples/Lumen.sxcu | 4 ++-- src/models.rs | 2 ++ src/routes/file.rs | 6 +++--- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/benches/upload.rs b/benches/upload.rs index 2f25620..b4ade13 100644 --- a/benches/upload.rs +++ b/benches/upload.rs @@ -6,8 +6,8 @@ use ureq::Agent; fn upload(agent: &Agent, api_key: &str, public_url: &str) { agent .post(&format!("{}/upload", public_url)) - .set("x_api_key", api_key) - .set("x_file_name", "test.png") + .set("x-api-key", api_key) + .set("x-file-name", "test.png") .set("content-type", "image/png") .send_bytes(&vec![0; 1024 * 1024]) .ok(); @@ -26,7 +26,7 @@ fn criterion_benchmark(c: &mut Criterion) { agent .post(&format!("{}/purge", public_url)) - .set("x_api_key", &api_key) + .set("x-api-key", &api_key) .call() .unwrap(); } diff --git a/examples/Lumen.sxcu b/examples/Lumen.sxcu index a8c5b6d..9aaf209 100644 --- a/examples/Lumen.sxcu +++ b/examples/Lumen.sxcu @@ -5,8 +5,8 @@ "requestMethod": "POST", "requestUrl": "http://localhost:8080/upload", "headers": { - "x_api_key": "API_KEY_HERE", - "x_file_name": "{filename}" + "x-api-key": "API_KEY_HERE", + "x-file-name": "{filename}" }, "body": "Binary", "url": "http://localhost:8080/{json:id}.{json:ext}?key={json:key}&nonce={json:nonce}", diff --git a/src/models.rs b/src/models.rs index 4b0cf00..cedc5a9 100644 --- a/src/models.rs +++ b/src/models.rs @@ -19,7 +19,9 @@ pub struct SXConfig { #[derive(Serialize, Deserialize)] pub struct SXHeaders { + #[serde(rename = "x-api-key")] x_api_key: String, + #[serde(rename = "x-file-name")] x_file_name: String, } diff --git a/src/routes/file.rs b/src/routes/file.rs index a9fe8e5..649979c 100644 --- a/src/routes/file.rs +++ b/src/routes/file.rs @@ -30,7 +30,7 @@ struct UploadResponse { #[post("/upload")] async fn upload(bytes: Bytes, req: HttpRequest, data: Data) -> impl Responder { - let api_key = req.headers().get("x_api_key"); + let api_key = req.headers().get("x-api-key"); if api_key.is_none() { return HttpResponse::Unauthorized().body("Invalid API key"); @@ -52,7 +52,7 @@ async fn upload(bytes: Bytes, req: HttpRequest, data: Data) -> impl Res return HttpResponse::PayloadTooLarge().body("Quota exceeded"); } - let file_name = req.headers().get("x_file_name"); + let file_name = req.headers().get("x-file-name"); if file_name.is_none() { return HttpResponse::BadRequest().body("Missing file name"); } @@ -222,7 +222,7 @@ async fn delete( #[post("/purge")] async fn purge(info: HttpRequest, data: Data) -> impl Responder { - let api_key = info.headers().get("x_api_key"); + let api_key = info.headers().get("x-api-key"); if api_key.is_none() { return HttpResponse::Unauthorized().body("Invalid API key");