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

Commit

Permalink
validate all 2xx status code in Webhook response #49 (#50)
Browse files Browse the repository at this point in the history
* Issue #49

using all 2XX response status as valid response, fixes #50 & fixes #49
  • Loading branch information
mathewlsm authored and lucaswin-amzn committed May 9, 2019
1 parent 488d63d commit 350515b
Showing 1 changed file with 10 additions and 1 deletion.
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<>(

This comment has been minimized.

Copy link
@ylwu-amzn

ylwu-amzn May 10, 2019

Contributor

Need to import import java.util.Set and java.util.HashSet and java.util.Arrays.
Should we use immutable set here? Collections.unmodifiableSet(new HashSet<>(...))

This comment has been minimized.

Copy link
@ylwu-amzn

ylwu-amzn May 10, 2019

Contributor

Will create a PR to fix it

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

0 comments on commit 350515b

Please sign in to comment.