bin: ch-remote: Generalise functions that work on a HTTP socket

Use the trait for Read/Write rather than specifying the concrete type.
This allows for the functionality to be used for different socket types.

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
Rob Bradford 2020-10-23 11:03:22 +01:00 committed by Sebastien Boeuf
parent a60b437f89
commit 654846f433

View File

@ -122,7 +122,7 @@ fn get_status_code(res: &str) -> Result<StatusCode, Error> {
}
}
fn parse_http_response(socket: &mut UnixStream) -> Result<Option<String>, Error> {
fn parse_http_response(socket: &mut dyn Read) -> Result<Option<String>, Error> {
let mut res = String::new();
let mut body_offset = None;
let mut content_length: Option<usize> = None;
@ -165,8 +165,8 @@ fn parse_http_response(socket: &mut UnixStream) -> Result<Option<String>, Error>
}
}
fn simple_api_command(
socket: &mut UnixStream,
fn simple_api_command<T: Read + Write>(
socket: &mut T,
method: &str,
c: &str,
request_body: Option<&str>,