Skip to content

Commit

Permalink
refactor: tiny code refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
bochaco committed Dec 27, 2024
1 parent a9c406e commit 3e5c363
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions src/docker_client.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
use super::{docker_msgs::*, node_instance::ContainerId};

use axum::body::Body;
use bytes::Bytes;
use futures_util::{pin_mut, Stream, StreamExt};
use http_body_util::BodyExt;
use hyper::{body::Incoming, client::conn, Method, Request, Response, StatusCode};
use hyper::{
body::Incoming,
client::conn,
header::{CONTENT_LENGTH, CONTENT_TYPE},
Method, Request, Response, StatusCode,
};
use hyper_util::rt::TokioIo;
use leptos::{logging, prelude::*};
use serde::Serialize;
Expand Down Expand Up @@ -537,7 +543,7 @@ impl DockerClient {
// consume and await end of response stream, discarding the bytes
get_response_bytes(resp).await?;

// FIXME: check if it succeeded and report error if it failed
// TODO: check if it succeeded and report error if it failed
//logging::log!("Formica image {NODE_CONTAINER_IMAGE_NAME} was successfully pulled!");
Ok(())
}
Expand Down Expand Up @@ -581,19 +587,15 @@ impl DockerClient {
let req = match method {
ReqMethod::Post(body_str) => req_builder
.method(Method::POST)
.header("Content-Type", "application/json")
.body(axum::body::Body::from(body_str.clone()))?,
.header(CONTENT_TYPE, "application/json")
.body(Body::from(body_str.clone()))?,
ReqMethod::Put(bytes) => req_builder
.header(hyper::header::CONTENT_TYPE, "application/octet-stream")
.header(hyper::header::CONTENT_LENGTH, bytes.len())
.header(CONTENT_TYPE, "application/octet-stream")
.header(CONTENT_LENGTH, bytes.len())
.method(Method::PUT)
.body(axum::body::Body::from(bytes.clone()))?,
ReqMethod::Get => req_builder
.method(Method::GET)
.body(axum::body::Body::from(()))?,
ReqMethod::Delete => req_builder
.method(Method::DELETE)
.body(axum::body::Body::from(()))?,
.body(Body::from(bytes.clone()))?,
ReqMethod::Get => req_builder.method(Method::GET).body(Body::from(()))?,
ReqMethod::Delete => req_builder.method(Method::DELETE).body(Body::from(()))?,
};

let resp = docker_reqs_sender.send_request(req).await?;
Expand Down

0 comments on commit 3e5c363

Please sign in to comment.