kopia lustrzana https://github.com/gaul/s3proxy
rodzic
71e2d61377
commit
bc2b18ee2b
|
@ -244,6 +244,10 @@ final class S3ProxyHandler extends AbstractHandler {
|
|||
ImmutableMap.<String, String>of());
|
||||
baseRequest.setHandled(true);
|
||||
return;
|
||||
} catch (HttpResponseException hre) {
|
||||
response.sendError(hre.getResponse().getStatusCode());
|
||||
baseRequest.setHandled(true);
|
||||
return;
|
||||
} catch (S3Exception se) {
|
||||
sendSimpleErrorResponse(request, response, se.getError(),
|
||||
se.getMessage(), se.getElements());
|
||||
|
@ -1116,6 +1120,29 @@ final class S3ProxyHandler extends AbstractHandler {
|
|||
throws IOException, S3Exception {
|
||||
int status = HttpServletResponse.SC_OK;
|
||||
GetOptions options = new GetOptions();
|
||||
|
||||
String ifMatch = request.getHeader(HttpHeaders.IF_MATCH);
|
||||
if (ifMatch != null) {
|
||||
options.ifETagMatches(ifMatch);
|
||||
}
|
||||
|
||||
String ifNoneMatch = request.getHeader(HttpHeaders.IF_NONE_MATCH);
|
||||
if (ifNoneMatch != null) {
|
||||
options.ifETagDoesntMatch(ifNoneMatch);
|
||||
}
|
||||
|
||||
long ifModifiedSince = request.getDateHeader(
|
||||
HttpHeaders.IF_MODIFIED_SINCE);
|
||||
if (ifModifiedSince != -1) {
|
||||
options.ifModifiedSince(new Date(ifModifiedSince));
|
||||
}
|
||||
|
||||
long ifUnmodifiedSince = request.getDateHeader(
|
||||
HttpHeaders.IF_UNMODIFIED_SINCE);
|
||||
if (ifUnmodifiedSince != -1) {
|
||||
options.ifUnmodifiedSince(new Date(ifUnmodifiedSince));
|
||||
}
|
||||
|
||||
String range = request.getHeader(HttpHeaders.RANGE);
|
||||
if (range != null && range.startsWith("bytes=") &&
|
||||
// ignore multiple ranges
|
||||
|
|
|
@ -49,9 +49,11 @@ import org.jclouds.blobstore.domain.MultipartUpload;
|
|||
import org.jclouds.blobstore.domain.PageSet;
|
||||
import org.jclouds.blobstore.domain.StorageMetadata;
|
||||
import org.jclouds.blobstore.options.CopyOptions;
|
||||
import org.jclouds.blobstore.options.GetOptions;
|
||||
import org.jclouds.blobstore.options.ListContainerOptions;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.http.HttpResponseException;
|
||||
import org.jclouds.io.ContentMetadata;
|
||||
import org.jclouds.io.ContentMetadataBuilder;
|
||||
import org.jclouds.io.Payload;
|
||||
|
@ -610,6 +612,29 @@ public final class S3ProxyTest {
|
|||
userMetadata);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConditionalGet() throws Exception {
|
||||
String blobName = "blob-name";
|
||||
Blob putBlob = s3BlobStore.blobBuilder(blobName)
|
||||
.payload(BYTE_SOURCE)
|
||||
.contentLength(BYTE_SOURCE.size())
|
||||
.build();
|
||||
String eTag = s3BlobStore.putBlob(containerName, putBlob);
|
||||
|
||||
Blob getBlob = s3BlobStore.getBlob(containerName, blobName,
|
||||
new GetOptions().ifETagMatches(eTag));
|
||||
assertThat(getBlob.getPayload()).isNotNull();
|
||||
|
||||
try {
|
||||
s3BlobStore.getBlob(containerName, blobName,
|
||||
new GetOptions().ifETagDoesntMatch(eTag));
|
||||
Fail.failBecauseExceptionWasNotThrown(HttpResponseException.class);
|
||||
} catch (HttpResponseException hre) {
|
||||
assertThat(hre.getResponse().getStatusCode()).isEqualTo(
|
||||
HttpServletResponse.SC_NOT_MODIFIED);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnknownParameter() throws Exception {
|
||||
final S3Client s3Client = s3Context.unwrapApi(S3Client.class);
|
||||
|
|
Ładowanie…
Reference in New Issue