Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

validate all 2xx status code in Webhook response #49 #50

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@ public class DestinationHttpClient {
private static final int TIMEOUT_MILLISECONDS = (int) TimeValue.timeValueSeconds(5).millis();
private static final int SOCKET_TIMEOUT_MILLISECONDS = (int)TimeValue.timeValueSeconds(50).millis();

/**
* all valid response status
*/
private static final Set<Integer> VALID_RESPONSE_STATUS = new HashSet<>(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Np: Should we call SUCCESS_RESPONSE_STATUS? To me all the http codes are valid(1XX, 3XX, 4XX)

Arrays.asList(RestStatus.OK.getStatus(), RestStatus.CREATED.getStatus(), RestStatus.ACCEPTED.getStatus(),
RestStatus.NON_AUTHORITATIVE_INFORMATION.getStatus(), RestStatus.NO_CONTENT.getStatus(),
RestStatus.RESET_CONTENT.getStatus(), RestStatus.PARTIAL_CONTENT.getStatus(),
RestStatus.MULTI_STATUS.getStatus()));

private static CloseableHttpClient HTTP_CLIENT = createHttpClient();

private static CloseableHttpClient createHttpClient() {
Expand Down Expand Up @@ -153,7 +162,7 @@ public String getResponseString(CloseableHttpResponse response) throws IOExcepti
private void validateResponseStatus(HttpResponse response) throws IOException {
int statusCode = response.getStatusLine().getStatusCode();

if (statusCode != RestStatus.OK.getStatus()) {
if (!(VALID_RESPONSE_STATUS.contains(statusCode))) {
throw new IOException("Failed: " + response);
}
}
Expand Down