Skip to content

Commit 4867b1b

Browse files
committed
feat: add way to make raw req and get url for BlockingClient
1 parent 6440e1d commit 4867b1b

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

src/blocking.rs

+14-8
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,13 @@ impl BlockingClient {
5151
}
5252
}
5353

54-
fn get_request(&self, path: &str) -> Result<Request, Error> {
54+
/// Get the underlying base URL.
55+
pub fn url(&self) -> &str {
56+
&self.url
57+
}
58+
59+
/// Perform a raw HTTP GET request with the given URI `path`.
60+
pub fn raw_get_request(&self, path: &str) -> Result<Request, Error> {
5561
let mut request = minreq::get(format!("{}{}", self.url, path));
5662

5763
if let Some(proxy) = &self.proxy {
@@ -73,7 +79,7 @@ impl BlockingClient {
7379
}
7480

7581
fn get_opt_response<T: Decodable>(&self, path: &str) -> Result<Option<T>, Error> {
76-
match self.get_request(path)?.send() {
82+
match self.raw_get_request(path)?.send() {
7783
Ok(resp) if is_status_not_found(resp.status_code) => Ok(None),
7884
Ok(resp) if !is_status_ok(resp.status_code) => {
7985
let status = u16::try_from(resp.status_code).map_err(Error::StatusCode)?;
@@ -86,7 +92,7 @@ impl BlockingClient {
8692
}
8793

8894
fn get_opt_response_txid(&self, path: &str) -> Result<Option<Txid>, Error> {
89-
match self.get_request(path)?.send() {
95+
match self.raw_get_request(path)?.send() {
9096
Ok(resp) if is_status_not_found(resp.status_code) => Ok(None),
9197
Ok(resp) if !is_status_ok(resp.status_code) => {
9298
let status = u16::try_from(resp.status_code).map_err(Error::StatusCode)?;
@@ -101,7 +107,7 @@ impl BlockingClient {
101107
}
102108

103109
fn get_opt_response_hex<T: Decodable>(&self, path: &str) -> Result<Option<T>, Error> {
104-
match self.get_request(path)?.send() {
110+
match self.raw_get_request(path)?.send() {
105111
Ok(resp) if is_status_not_found(resp.status_code) => Ok(None),
106112
Ok(resp) if !is_status_ok(resp.status_code) => {
107113
let status = u16::try_from(resp.status_code).map_err(Error::StatusCode)?;
@@ -120,7 +126,7 @@ impl BlockingClient {
120126
}
121127

122128
fn get_response_hex<T: Decodable>(&self, path: &str) -> Result<T, Error> {
123-
match self.get_request(path)?.send() {
129+
match self.raw_get_request(path)?.send() {
124130
Ok(resp) if !is_status_ok(resp.status_code) => {
125131
let status = u16::try_from(resp.status_code).map_err(Error::StatusCode)?;
126132
let message = resp.as_str().unwrap_or_default().to_string();
@@ -139,7 +145,7 @@ impl BlockingClient {
139145
&'a self,
140146
path: &'a str,
141147
) -> Result<T, Error> {
142-
let response = self.get_request(path)?.send();
148+
let response = self.raw_get_request(path)?.send();
143149
match response {
144150
Ok(resp) if !is_status_ok(resp.status_code) => {
145151
let status = u16::try_from(resp.status_code).map_err(Error::StatusCode)?;
@@ -155,7 +161,7 @@ impl BlockingClient {
155161
&self,
156162
path: &str,
157163
) -> Result<Option<T>, Error> {
158-
match self.get_request(path)?.send() {
164+
match self.raw_get_request(path)?.send() {
159165
Ok(resp) if is_status_not_found(resp.status_code) => Ok(None),
160166
Ok(resp) if !is_status_ok(resp.status_code) => {
161167
let status = u16::try_from(resp.status_code).map_err(Error::StatusCode)?;
@@ -168,7 +174,7 @@ impl BlockingClient {
168174
}
169175

170176
fn get_response_str(&self, path: &str) -> Result<String, Error> {
171-
match self.get_request(path)?.send() {
177+
match self.raw_get_request(path)?.send() {
172178
Ok(resp) if !is_status_ok(resp.status_code) => {
173179
let status = u16::try_from(resp.status_code).map_err(Error::StatusCode)?;
174180
let message = resp.as_str().unwrap_or_default().to_string();

0 commit comments

Comments
 (0)