Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compatibility fixes and a standalone mockhsm example #529

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
http: fix the connector /status format
Each line is "key=value\n", including the final line:

    $ curl http://localhost:12345/connector/status
    status=OK
    serial=*
    version=3.0.2
    pid=54209
    address=localhost
    port=12345
  • Loading branch information
nholstein committed Mar 9, 2024
commit 512013a7bfdfb0be2d64a14efebfbdcfb7ac26ca
11 changes: 5 additions & 6 deletions src/connector/http/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use crate::{
},
uuid,
};
use std::{io, process, time::Instant};
use std::{fmt::Write, io, process, time::Instant};
use tiny_http as http;

/// `yubihsm-connector` compatible HTTP server
Expand Down Expand Up @@ -107,11 +107,10 @@ impl Server {
("port", &self.port.to_string()),
];

let body = status
.iter()
.map(|(k, v)| [*k, *v].join("\n"))
.collect::<Vec<_>>()
.join("\n");
let body = status.iter().fold(String::new(), |mut body, (k, v)| {
let _ = writeln!(body, "{k}={v}");
body
});

Ok(http::Response::from_string(body))
}
Expand Down