use hyper::header::{CONTENT_LENGTH, CONTENT_TYPE};
use hyper::{Request, Body, client::Client};

use crate::errors::RequestError;

#[derive(Clone, Debug)]
pub struct Action(String);

impl Action {
    pub fn new(action: &str) -> Action {
        Action(action.into())
    }
}

const HEADER_NAME: &str = "SOAPAction";

pub async fn send_async(
    url: &str,
    action: Action,
    body: &str,
) -> Result<String, RequestError> {

    let client = Client::new();

    let req = Request::builder()
        .uri(url)
        .method("POST")
        .header(HEADER_NAME, action.0)
        .header(CONTENT_TYPE, "xml")
        .header(CONTENT_LENGTH, body.len() as u64)
        .body(Body::from(body.to_string()))?;

    let resp = client.request(req).await?;
    let body = hyper::body::to_bytes(resp.into_body()).await?;
    let string = String::from_utf8(body.to_vec())?;
    Ok(string)
}

use hyper::header::{CONTENT_LENGTH, CONTENT_TYPE};
use hyper::{Request, Body, client::Client};

use crate::errors::RequestError;

#[derive(Clone, Debug)]
pub struct Action(String);

impl Action {
    pub fn new(action: &str) -> Action {
        Action(action.into())
    }
}

const HEADER_NAME: &str = "SOAPAction";

pub async fn send_async(
    url: &str,
    action: Action,
    body: &str,
) -> Result<String, RequestError> {

    let client = Client::new();

    let req = Request::builder()
        .uri(url)
        .method("POST")
        .header(HEADER_NAME, action.0)
        .header(CONTENT_TYPE, "text/xml")
        .header(CONTENT_LENGTH, body.len() as u64)
        .body(Body::from(body.to_string()))?;

    let resp = client.request(req).await?;
    let body = hyper::body::to_bytes(resp.into_body()).await?;
    let string = String::from_utf8(body.to_vec())?;
    Ok(string)
}

Fix SOAP request mime type
Fix SOAP request mime type
