1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
use crate::{IntoUrl, Ollama};
pub use http::header::*;
impl Ollama {
/// Creates a new `Ollama` instance with the specified host, port, and request headers.
///
/// # Arguments
///
/// * `host` - The host of the Ollama service.
/// * `port` - The port of the Ollama service.
/// * `headers` - The request headers to be used.
///
/// # Returns
///
/// A new `Ollama` instance with the specified request headers.
///
/// # Panics
///
/// Panics if the host is not a valid URL or if the URL cannot have a port.
pub fn new_with_request_headers(host: impl IntoUrl, port: u16, headers: HeaderMap) -> Self {
let mut ollama = Self::builder().host(host).port(port).build();
ollama.set_headers(Some(headers));
ollama
}
/// Sets the request headers for the `Ollama` instance.
///
/// # Arguments
///
/// * `headers` - An optional `HeaderMap` containing the request headers.
///
/// If `None` is provided, the headers will be reset to an empty `HeaderMap`.
pub fn set_headers(&mut self, headers: Option<HeaderMap>) {
match headers {
Some(h) => self.request_headers = h,
None => self.request_headers = HeaderMap::new(),
}
}
}