chore: ensure all http/1.1 requests are properly structured

This commit is contained in:
Brice Dobry
2024-03-11 13:15:58 -04:00
parent 52f2c99bfe
commit 17656a3863
2 changed files with 17 additions and 5 deletions

View File

@@ -226,11 +226,15 @@ impl EventStopSignaler for SignerStopSignaler {
// We need to send actual data to trigger the event receiver
let body = "Yo. Shut this shit down!".to_string();
let req = format!(
"POST /shutdown HTTP/1.1\r\nContent-Length: {}\r\n\r\n{}",
&body.len(),
"POST /shutdown HTTP/1.1\r\nHost: {}\r\nConnection: close\r\nContent-Length: {}\r\nContent-Type: text/plain\r\n\r\n{}",
self.local_addr,
body.len(),
body
);
stream.write_all(req.as_bytes()).unwrap();
match stream.write_all(req.as_bytes()) {
Err(e) => error!("Failed to send shutdown request: {}", e),
_ => (),
};
}
}
}

View File

@@ -135,7 +135,12 @@ fn test_simple_signer() {
let ev = &thread_chunks[num_sent];
let body = serde_json::to_string(ev).unwrap();
let req = format!("POST /stackerdb_chunks HTTP/1.1\r\nConnection: close\r\nContent-Length: {}\r\n\r\n{}", &body.len(), body);
let req = format!(
"POST /stackerdb_chunks HTTP/1.1\r\nHost: {}\r\nConnection: close\r\nContent-Type: application/json\r\nContent-Length: {}\r\n\r\n{}",
endpoint,
&body.len(),
body
);
debug!("Send:\n{}", &req);
sock.write_all(req.as_bytes()).unwrap();
@@ -188,7 +193,10 @@ fn test_status_endpoint() {
return;
}
};
let req = "GET /status HTTP/1.1\r\nConnection: close\r\n\r\n";
let req = format!(
"GET /status HTTP/1.1\r\nHost: {}\r\nConnection: close\r\n\r\n",
endpoint
);
sock.write_all(req.as_bytes()).unwrap();
let mut buf = [0; 128];