From 4331a5cb85a6d5d0327b347963f9fa4656e8529e Mon Sep 17 00:00:00 2001 From: Xander Bil Date: Sat, 29 Jun 2024 22:16:34 +0200 Subject: [PATCH] respond with correct content-type matching accept header --- src/controllers/users_controller.rs | 7 +++++-- templates/users/keys.html | 1 + tests/users.rs | 1 + 3 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 templates/users/keys.html diff --git a/src/controllers/users_controller.rs b/src/controllers/users_controller.rs index 827dde7..c4b1187 100644 --- a/src/controllers/users_controller.rs +++ b/src/controllers/users_controller.rs @@ -63,7 +63,7 @@ pub async fn show_user<'r>( pub async fn show_ssh_key<'r>( db: DbConn, username: String, -) -> Result>> { +) -> Result> { let user = User::find_by_username(username, &db).await?; let mut keys = vec![]; if let Some(ssh_keys) = user.ssh_key { @@ -74,7 +74,10 @@ pub async fn show_ssh_key<'r>( } } } - Ok(Json(keys)) + Ok(Accepter { + html: template!("users/keys.html"; keys: String = keys.join("\n")), + json: Json(keys), + }) } #[get("/users")] diff --git a/templates/users/keys.html b/templates/users/keys.html new file mode 100644 index 0000000..c907385 --- /dev/null +++ b/templates/users/keys.html @@ -0,0 +1 @@ +
{{keys}}
diff --git a/tests/users.rs b/tests/users.rs index 816e450..a01e2ad 100644 --- a/tests/users.rs +++ b/tests/users.rs @@ -1039,6 +1039,7 @@ async fn get_keys() { let response = http_client .get(format!("/users/{}/keys", user.username)) + .header(Accept::JSON) .dispatch() .await;