@Test(expectedExceptions = ProtocolException.class) public void throwsWhenResponseHasIncorrectContentRange() throws Exception { final HttpRange.Response badContentRange = new HttpRange.Response(0, 99, 100); HttpDownloadContinuationMarker.validateInitialExchange(ImmutablePair.of(STUB_ETAG, STUB_BOUNDED_REQUEST_RANGE), SC_PARTIAL_CONTENT, ImmutablePair.of(STUB_ETAG, badContentRange)); }
static HttpDownloadContinuationMarker validateInitialExchange(final Pair<String, Request> requestHints, final int responseCode, final Pair<String, Response> responseFingerprint) throws ProtocolException { if (requestHints.getLeft() != null && !requestHints.getLeft().equals(responseFingerprint.getLeft())) { throw new ProtocolException( String.format( "ETag does not match If-Match: If-Match [%s], ETag [%s]", requestHints.getLeft(), responseFingerprint.getLeft())); } final boolean rangeRequest = requestHints.getRight() != null; if (rangeRequest && !requestHints.getRight().matches(responseFingerprint.getRight())) { throw new ProtocolException( String.format( "Content-Range does not match Request range: Range [%s], Content-Range [%s]", requestHints.getRight(), responseFingerprint.getRight())); } if (rangeRequest && responseCode != SC_PARTIAL_CONTENT) { throw new ProtocolException( String.format( "Unexpected response code for range request: expected [%d], got [%d]", SC_PARTIAL_CONTENT, responseCode)); } if (!rangeRequest && responseCode != SC_OK) { throw new ProtocolException( String.format( "Unexpected response code for non-range request: expected [%d], got [%d]", SC_OK, responseCode)); } return new HttpDownloadContinuationMarker(responseFingerprint.getLeft(), responseFingerprint.getRight()); }
HttpDownloadContinuationMarker { static HttpDownloadContinuationMarker validateInitialExchange(final Pair<String, Request> requestHints, final int responseCode, final Pair<String, Response> responseFingerprint) throws ProtocolException { if (requestHints.getLeft() != null && !requestHints.getLeft().equals(responseFingerprint.getLeft())) { throw new ProtocolException( String.format( "ETag does not match If-Match: If-Match [%s], ETag [%s]", requestHints.getLeft(), responseFingerprint.getLeft())); } final boolean rangeRequest = requestHints.getRight() != null; if (rangeRequest && !requestHints.getRight().matches(responseFingerprint.getRight())) { throw new ProtocolException( String.format( "Content-Range does not match Request range: Range [%s], Content-Range [%s]", requestHints.getRight(), responseFingerprint.getRight())); } if (rangeRequest && responseCode != SC_PARTIAL_CONTENT) { throw new ProtocolException( String.format( "Unexpected response code for range request: expected [%d], got [%d]", SC_PARTIAL_CONTENT, responseCode)); } if (!rangeRequest && responseCode != SC_OK) { throw new ProtocolException( String.format( "Unexpected response code for non-range request: expected [%d], got [%d]", SC_OK, responseCode)); } return new HttpDownloadContinuationMarker(responseFingerprint.getLeft(), responseFingerprint.getRight()); } }
HttpDownloadContinuationMarker { static HttpDownloadContinuationMarker validateInitialExchange(final Pair<String, Request> requestHints, final int responseCode, final Pair<String, Response> responseFingerprint) throws ProtocolException { if (requestHints.getLeft() != null && !requestHints.getLeft().equals(responseFingerprint.getLeft())) { throw new ProtocolException( String.format( "ETag does not match If-Match: If-Match [%s], ETag [%s]", requestHints.getLeft(), responseFingerprint.getLeft())); } final boolean rangeRequest = requestHints.getRight() != null; if (rangeRequest && !requestHints.getRight().matches(responseFingerprint.getRight())) { throw new ProtocolException( String.format( "Content-Range does not match Request range: Range [%s], Content-Range [%s]", requestHints.getRight(), responseFingerprint.getRight())); } if (rangeRequest && responseCode != SC_PARTIAL_CONTENT) { throw new ProtocolException( String.format( "Unexpected response code for range request: expected [%d], got [%d]", SC_PARTIAL_CONTENT, responseCode)); } if (!rangeRequest && responseCode != SC_OK) { throw new ProtocolException( String.format( "Unexpected response code for non-range request: expected [%d], got [%d]", SC_OK, responseCode)); } return new HttpDownloadContinuationMarker(responseFingerprint.getLeft(), responseFingerprint.getRight()); } HttpDownloadContinuationMarker(final String etag,
                                   final Response initialContentRange); }
HttpDownloadContinuationMarker { static HttpDownloadContinuationMarker validateInitialExchange(final Pair<String, Request> requestHints, final int responseCode, final Pair<String, Response> responseFingerprint) throws ProtocolException { if (requestHints.getLeft() != null && !requestHints.getLeft().equals(responseFingerprint.getLeft())) { throw new ProtocolException( String.format( "ETag does not match If-Match: If-Match [%s], ETag [%s]", requestHints.getLeft(), responseFingerprint.getLeft())); } final boolean rangeRequest = requestHints.getRight() != null; if (rangeRequest && !requestHints.getRight().matches(responseFingerprint.getRight())) { throw new ProtocolException( String.format( "Content-Range does not match Request range: Range [%s], Content-Range [%s]", requestHints.getRight(), responseFingerprint.getRight())); } if (rangeRequest && responseCode != SC_PARTIAL_CONTENT) { throw new ProtocolException( String.format( "Unexpected response code for range request: expected [%d], got [%d]", SC_PARTIAL_CONTENT, responseCode)); } if (!rangeRequest && responseCode != SC_OK) { throw new ProtocolException( String.format( "Unexpected response code for non-range request: expected [%d], got [%d]", SC_OK, responseCode)); } return new HttpDownloadContinuationMarker(responseFingerprint.getLeft(), responseFingerprint.getRight()); } HttpDownloadContinuationMarker(final String etag,
                                   final Response initialContentRange); @Override String toString(); }
HttpDownloadContinuationMarker { static HttpDownloadContinuationMarker validateInitialExchange(final Pair<String, Request> requestHints, final int responseCode, final Pair<String, Response> responseFingerprint) throws ProtocolException { if (requestHints.getLeft() != null && !requestHints.getLeft().equals(responseFingerprint.getLeft())) { throw new ProtocolException( String.format( "ETag does not match If-Match: If-Match [%s], ETag [%s]", requestHints.getLeft(), responseFingerprint.getLeft())); } final boolean rangeRequest = requestHints.getRight() != null; if (rangeRequest && !requestHints.getRight().matches(responseFingerprint.getRight())) { throw new ProtocolException( String.format( "Content-Range does not match Request range: Range [%s], Content-Range [%s]", requestHints.getRight(), responseFingerprint.getRight())); } if (rangeRequest && responseCode != SC_PARTIAL_CONTENT) { throw new ProtocolException( String.format( "Unexpected response code for range request: expected [%d], got [%d]", SC_PARTIAL_CONTENT, responseCode)); } if (!rangeRequest && responseCode != SC_OK) { throw new ProtocolException( String.format( "Unexpected response code for non-range request: expected [%d], got [%d]", SC_OK, responseCode)); } return new HttpDownloadContinuationMarker(responseFingerprint.getLeft(), responseFingerprint.getRight()); } HttpDownloadContinuationMarker(final String etag,
                                   final Response initialContentRange); @Override String toString();  }