Skip to content
Merged
Show file tree
Hide file tree
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
12 changes: 12 additions & 0 deletions elasticsearch/src/http/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use crate::{
http::{headers::HeaderMap, Method, StatusCode, Url},
};
use serde::de::DeserializeOwned;
use std::fmt;

/// A response from Elasticsearch
pub struct Response(reqwest::Response, Method);
Expand Down Expand Up @@ -120,3 +121,14 @@ impl Response {
.map(|w| w.to_str().unwrap())
}
}

impl fmt::Debug for Response {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("Response")
.field("method", &self.method())
.field("url", self.url())
.field("status_code", &self.status_code())
.field("headers", self.headers())
.finish()
}
}
6 changes: 6 additions & 0 deletions elasticsearch/tests/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,12 @@ async fn search_with_body() -> Result<(), failure::Error> {
assert_eq!(response.url(), &expected_url);
assert_eq!(response.status_code(), StatusCode::OK);
assert_eq!(response.method(), elasticsearch::http::Method::Post);
let debug = format!("{:?}", &response);
assert_eq!(
format!("Response {{ method: Post, url: \"{}\", status_code: 200, headers: {{\"content-type\": \"application/json; charset=UTF-8\"}} }}",
expected_url.as_str()),
debug);

let response_body = response.json::<Value>().await?;
assert!(response_body["took"].as_i64().is_some());

Expand Down