mirror of
https://github.com/mii443/rust.git
synced 2025-08-22 16:25:37 +00:00
add: default header
This commit is contained in:
@ -9,7 +9,7 @@ use std::{io::Write, fs::File};
|
|||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> Result<()> {
|
async fn main() -> Result<()> {
|
||||||
let client = Client::new("http://localhost:50021".to_string());
|
let client = Client::new("http://localhost:50021".to_string(), None);
|
||||||
let audio_query = client
|
let audio_query = client
|
||||||
.create_audio_query("こんにちは", 1, None)
|
.create_audio_query("こんにちは", 1, None)
|
||||||
.await?;
|
.await?;
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
use voicevox_client::Client;
|
use voicevox_client::Client;
|
||||||
use reqwest::Result;
|
use reqwest::{Result, header::HeaderMap};
|
||||||
use std::{io::Write, fs::File};
|
use std::{io::Write, fs::File};
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> Result<()> {
|
async fn main() -> Result<()> {
|
||||||
let client = Client::new("http://localhost:50021".to_string());
|
let client = Client::new("http://localhost:50021".to_string(), None);
|
||||||
let audio_query = client
|
let audio_query = client
|
||||||
.create_audio_query("こんにちは", 1, None)
|
.create_audio_query("こんにちは", 1, None)
|
||||||
.await?;
|
.await?;
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
use crate::{audio_query::AudioQuery, restapi::RestAPI, types::audio_query::AudioQueryType};
|
use crate::{audio_query::AudioQuery, restapi::RestAPI, types::audio_query::AudioQueryType};
|
||||||
use reqwest::Result;
|
use reqwest::{Result, header::HeaderMap};
|
||||||
|
|
||||||
pub struct Client {
|
pub struct Client {
|
||||||
restapi: RestAPI,
|
restapi: RestAPI,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Client {
|
impl Client {
|
||||||
pub fn new(base_path: String) -> Self {
|
pub fn new(base_path: String, headers: Option<HeaderMap>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
restapi: RestAPI::new(base_path),
|
restapi: RestAPI::new(base_path, headers),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use crate::types::audio_query::AudioQueryType;
|
use crate::types::audio_query::AudioQueryType;
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
use reqwest::{Client, RequestBuilder, Result};
|
use reqwest::{Client, RequestBuilder, Result, header::HeaderMap};
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct RestAPI {
|
pub struct RestAPI {
|
||||||
@ -9,10 +9,15 @@ pub struct RestAPI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl RestAPI {
|
impl RestAPI {
|
||||||
pub fn new(base_path: String) -> Self {
|
pub fn new(base_path: String, headers: Option<HeaderMap>) -> Self {
|
||||||
|
let mut client_builder = Client::builder();
|
||||||
|
if let Some(headers) = headers {
|
||||||
|
client_builder = client_builder.default_headers(headers);
|
||||||
|
}
|
||||||
|
let client = client_builder.build().unwrap();
|
||||||
Self {
|
Self {
|
||||||
base_path,
|
base_path,
|
||||||
client: Client::new(),
|
client,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user