-
Notifications
You must be signed in to change notification settings - Fork 25.6k
REST client: introduce a strict deprecation mode #33708
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
47f45cb
ef1c4ea
38202c9
514ef27
486698e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,7 +26,11 @@ | |
| import org.apache.http.RequestLine; | ||
| import org.apache.http.StatusLine; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import java.util.Objects; | ||
| import java.util.regex.Matcher; | ||
| import java.util.regex.Pattern; | ||
|
|
||
| /** | ||
| * Holds an elasticsearch response. It wraps the {@link HttpResponse} returned and associates it with | ||
|
|
@@ -96,6 +100,46 @@ public HttpEntity getEntity() { | |
| return response.getEntity(); | ||
| } | ||
|
|
||
| private static final Pattern WARNING_HEADER_PATTERN = Pattern.compile( | ||
| "299 " + // warn code | ||
| "Elasticsearch-\\d+\\.\\d+\\.\\d+(?:-(?:alpha|beta|rc)\\d+)?(?:-SNAPSHOT)?-(?:[a-f0-9]{7}|Unknown) " + // warn agent | ||
| "\"((?:\t| |!|[\\x23-\\x5B]|[\\x5D-\\x7E]|[\\x80-\\xFF]|\\\\|\\\\\")*)\" " + // quoted warning value, captured | ||
| // quoted RFC 1123 date format | ||
| "\"" + // opening quote | ||
| "(?:Mon|Tue|Wed|Thu|Fri|Sat|Sun), " + // weekday | ||
| "\\d{2} " + // 2-digit day | ||
| "(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) " + // month | ||
| "\\d{4} " + // 4-digit year | ||
| "\\d{2}:\\d{2}:\\d{2} " + // (two-digit hour):(two-digit minute):(two-digit second) | ||
| "GMT" + // GMT | ||
| "\""); // closing quote | ||
|
|
||
| /** | ||
| * Returns a list of all warning headers returned in the response. | ||
| */ | ||
| public List<String> getWarnings() { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you add javadoc for this? |
||
| List<String> warnings = new ArrayList<>(); | ||
| for (Header header : response.getHeaders("Warning")) { | ||
| String warning = header.getValue(); | ||
| final Matcher matcher = WARNING_HEADER_PATTERN.matcher(warning); | ||
| if (matcher.matches()) { | ||
| warnings.add(matcher.group(1)); | ||
| continue; | ||
| } | ||
| warnings.add(warning); | ||
| } | ||
| return warnings; | ||
| } | ||
|
|
||
| /** | ||
| * Returns true if there is at least one warning header returned in the | ||
| * response. | ||
| */ | ||
| public boolean hasWarnings() { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And could you add javadoc for this too? |
||
| Header[] warnings = response.getHeaders("Warning"); | ||
| return warnings != null && warnings.length > 0; | ||
| } | ||
|
|
||
| HttpResponse getHttpResponse() { | ||
| return response; | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -58,6 +58,10 @@ private static String buildMessage(Response response) throws IOException { | |
| response.getStatusLine().toString() | ||
| ); | ||
|
|
||
| if (response.hasWarnings()) { | ||
| message += "\n" + "Warnings: " + response.getWarnings(); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
| } | ||
|
|
||
| HttpEntity entity = response.getEntity(); | ||
| if (entity != null) { | ||
| if (entity.isRepeatable() == false) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you line all of these up vertically?