Skip to content

Commit 0f3efdf

Browse files
committed
Add deprecation warning headers (#88)
This commit adds a deprecation warnings headers fn to Response, to easily read the headers from the response. (cherry picked from commit 7beb3f0)
1 parent 3713c03 commit 0f3efdf

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

elasticsearch/src/http/response.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,18 @@ impl Response {
4040
self.0.headers()
4141
}
4242

43+
/// Gets the Deprecation warning response headers
44+
///
45+
/// Deprecation headers signal the use of Elasticsearch functionality
46+
/// or features that are deprecated and will be removed in a future release.
47+
pub fn warning_headers(&self) -> impl Iterator<Item = &str> {
48+
self.0
49+
.headers()
50+
.get_all("Warning")
51+
.iter()
52+
.map(|w| w.to_str().unwrap())
53+
}
54+
4355
/// Asynchronously reads the response body as JSON
4456
///
4557
/// Reading the response body consumes `self`

elasticsearch/tests/client.rs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,49 @@ async fn x_opaque_id_header() -> Result<(), failure::Error> {
8787
Ok(())
8888
}
8989

90+
#[tokio::test]
91+
async fn deprecation_warning_headers() -> Result<(), failure::Error> {
92+
let client = client::create_default();
93+
let _ = index_documents(&client).await?;
94+
let response = client
95+
.search(SearchParts::None)
96+
.body(json!{
97+
{
98+
"aggs": {
99+
"titles": {
100+
"terms": {
101+
"field": "title.keyword",
102+
"order": [{
103+
"_term": "asc"
104+
}]
105+
}
106+
}
107+
},
108+
"query": {
109+
"function_score": {
110+
"functions": [{
111+
"random_score": {
112+
"seed": 1337
113+
}
114+
}],
115+
"query": {
116+
"match_all": {}
117+
}
118+
}
119+
},
120+
"size": 0
121+
}
122+
})
123+
.send()
124+
.await?;
125+
126+
let warnings = response.warning_headers().collect::<Vec<&str>>();
127+
assert!(warnings.len() > 0);
128+
assert!(warnings.iter().any(|&w| w.contains("Deprecated aggregation order key")));
129+
130+
Ok(())
131+
}
132+
90133
#[tokio::test]
91134
async fn serialize_querystring() -> Result<(), failure::Error> {
92135
let server = server::http(move |req| async move {

0 commit comments

Comments
 (0)