From 21bb5eb39a4fab2da9a579954d885031e7ddc50d Mon Sep 17 00:00:00 2001 From: Evan Williams Date: Tue, 29 Jan 2019 13:47:14 -0500 Subject: [PATCH] Allow 204s The current code code of the uploadChunk method allowed 200 and 202 as valid response codes. However, the server also sends 204s and the method incorrectly identified this as an error. This commit corrects that. --- .../rest/client/impl/DefaultInterFAXClient.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/main/java/net/interfax/rest/client/impl/DefaultInterFAXClient.java b/src/main/java/net/interfax/rest/client/impl/DefaultInterFAXClient.java index 6e37c39..f40152f 100644 --- a/src/main/java/net/interfax/rest/client/impl/DefaultInterFAXClient.java +++ b/src/main/java/net/interfax/rest/client/impl/DefaultInterFAXClient.java @@ -390,11 +390,14 @@ public APIResponse uploadChunk(String uploadChunkToDocumentEndpoint, .header("Range", "bytes="+startByteRange+"-"+endByteRange) .post(Entity.entity(bytesToUpload, MediaType.APPLICATION_OCTET_STREAM_TYPE)); - int expectedResponseCode = lastChunk ? - Response.Status.OK.getStatusCode(): - Response.Status.ACCEPTED.getStatusCode(); - if (response.getStatus() == expectedResponseCode) { + final int OK = Response.Status.OK.getStatusCode(); + final int ACCEPTED = Response.Status.ACCEPTED.getStatusCode(); + final int NO_CONTENT = Response.Status.NO_CONTENT.getStatusCode(); // 204: No content + + + if ((lastChunk && response.getStatus() == OK) || + (!lastChunk && (response.getStatus() == ACCEPTED || response.getStatus() == NO_CONTENT))) { log.info( "chunk uploaded at {}; totalByesUploaded = {}; lastChunk = {}", uploadChunkToDocumentEndpoint,