use reqwest::header::CONTENT_TYPE;
use reqwest::Client;
use crate::error::Result;
use crate::udp_server::Request;
pub struct Upstream<'a> {
client: &'a Client,
url: &'a str,
}
impl<'a> Upstream<'a> {
pub fn new(client: &'a Client, url: &'a str) -> Upstream<'a> {
Upstream { client, url }
}
pub async fn send(&self, request: &Request) -> Result<Vec<u8>> {
let response = self
.client
.post(self.url)
.header(CONTENT_TYPE, "application/dns-message")
.body(request.body.to_owned())
.send()
.await?;
Ok(response.bytes().await?.to_vec())
}
}