Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 9 additions & 14 deletions src/sinks/databend/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,19 +111,8 @@ impl DatabendAPIClient {

async fn do_request(
&self,
url: String,
req: Option<DatabendHttpRequest>,
mut request: Request<Body>,
) -> Result<DatabendHttpResponse, DatabendError> {
let body = match req {
Some(r) => {
let body = serde_json::to_vec(&r)?;
Body::from(body)
}
None => Body::empty(),
};
let mut request = Request::post(url)
.header("Content-Type", "application/json")
.body(body)?;
if let Some(a) = &self.auth {
a.apply(&mut request);
}
Expand Down Expand Up @@ -163,15 +152,21 @@ impl DatabendAPIClient {
next_uri: String,
) -> Result<DatabendHttpResponse, DatabendError> {
let endpoint = self.get_page_endpoint(&next_uri)?;
self.do_request(endpoint, None).await
let request = Request::get(endpoint)
.header("Content-Type", "application/json")
.body(Body::empty())?;
self.do_request(request).await
}

pub(super) async fn query(
&self,
req: DatabendHttpRequest,
) -> Result<DatabendHttpResponse, DatabendError> {
let endpoint = self.get_query_endpoint()?;
let resp = self.do_request(endpoint, Some(req)).await?;
let request = Request::post(endpoint)
.header("Content-Type", "application/json")
.body(Body::from(serde_json::to_vec(&req)?))?;
let resp = self.do_request(request).await?;
match resp.next_uri {
None => Ok(resp),
Some(_) => {
Expand Down