Skip to content

Commit

Permalink
respond with correct content-type matching accept header
Browse files Browse the repository at this point in the history
  • Loading branch information
xerbalind committed Jun 29, 2024
1 parent aaeb9d3 commit 4331a5c
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/controllers/users_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ pub async fn show_user<'r>(
pub async fn show_ssh_key<'r>(
db: DbConn,
username: String,
) -> Result<Json<Vec<String>>> {
) -> Result<impl Responder<'r, 'static>> {
let user = User::find_by_username(username, &db).await?;
let mut keys = vec![];
if let Some(ssh_keys) = user.ssh_key {
Expand All @@ -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")]
Expand Down
1 change: 1 addition & 0 deletions templates/users/keys.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<pre>{{keys}}</pre>
1 change: 1 addition & 0 deletions tests/users.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1039,6 +1039,7 @@ async fn get_keys() {

let response = http_client
.get(format!("/users/{}/keys", user.username))
.header(Accept::JSON)
.dispatch()
.await;

Expand Down

0 comments on commit 4331a5c

Please sign in to comment.