37 lines
990 B
Rust
37 lines
990 B
Rust
use crate::fat_error::FatResult;
|
|
use crate::log::LOG_ACCESS;
|
|
use edge_http::io::server::Connection;
|
|
use edge_nal::io::{Read, Write};
|
|
|
|
pub(crate) async fn get_log<T, const N: usize>(
|
|
conn: &mut Connection<'_, T, N>,
|
|
) -> FatResult<Option<u32>>
|
|
where
|
|
T: Read + Write,
|
|
{
|
|
let log = LOG_ACCESS.lock().await.get();
|
|
conn.initiate_response(
|
|
200,
|
|
Some("OK"),
|
|
&[
|
|
("Content-Type", "text/javascript"),
|
|
("Access-Control-Allow-Origin", "*"),
|
|
("Access-Control-Allow-Headers", "*"),
|
|
("Access-Control-Allow-Methods", "*"),
|
|
],
|
|
)
|
|
.await?;
|
|
conn.write_all("[".as_bytes()).await?;
|
|
let mut append = false;
|
|
for entry in log {
|
|
if append {
|
|
conn.write_all(",".as_bytes()).await?;
|
|
}
|
|
append = true;
|
|
let json = serde_json::to_string(&entry)?;
|
|
conn.write_all(json.as_bytes()).await?;
|
|
}
|
|
conn.write_all("]".as_bytes()).await?;
|
|
Ok(Some(200))
|
|
}
|