Skip to content

Commit

Permalink
fix!: headers cannot have _ in them.
Browse files Browse the repository at this point in the history
  • Loading branch information
ChecksumDev committed Oct 22, 2023
1 parent e8ab899 commit 3d0b00b
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
6 changes: 3 additions & 3 deletions benches/upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
}
Expand Down
4 changes: 2 additions & 2 deletions examples/Lumen.sxcu
Original file line number Diff line number Diff line change
Expand Up @@ -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}",
Expand Down
2 changes: 2 additions & 0 deletions src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand Down
6 changes: 3 additions & 3 deletions src/routes/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ struct UploadResponse {

#[post("/upload")]
async fn upload(bytes: Bytes, req: HttpRequest, data: Data<AppData>) -> 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");
Expand All @@ -52,7 +52,7 @@ async fn upload(bytes: Bytes, req: HttpRequest, data: Data<AppData>) -> 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");
}
Expand Down Expand Up @@ -222,7 +222,7 @@ async fn delete(

#[post("/purge")]
async fn purge(info: HttpRequest, data: Data<AppData>) -> 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");
Expand Down

0 comments on commit 3d0b00b

Please sign in to comment.