Skip to content

Commit

Permalink
Return response object for GET.
Browse files Browse the repository at this point in the history
  • Loading branch information
dkocher committed Jul 8, 2017
1 parent 740852c commit 1899392
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/main/java/ch/iterate/openstack/swift/Client.java
Expand Up @@ -67,7 +67,6 @@
import ch.iterate.openstack.swift.handler.DefaultResponseHandler;
import ch.iterate.openstack.swift.handler.ObjectMetadataResponseHandler;
import ch.iterate.openstack.swift.handler.ObjectResponseHandler;
import ch.iterate.openstack.swift.io.ContentLengthInputStream;
import ch.iterate.openstack.swift.io.SubInputStream;
import ch.iterate.openstack.swift.method.Authentication10UsernameKeyRequest;
import ch.iterate.openstack.swift.method.Authentication11UsernameKeyRequest;
Expand Down Expand Up @@ -1479,11 +1478,11 @@ public ContainerMetadata getContainerMetaData(Region region, String container) t
* @return An input stream that will give the objects content when read from.
* @throws GenericException Unexpected response
*/
public ContentLengthInputStream getObject(Region region, String container, String object) throws IOException {
public Response getObject(Region region, String container, String object) throws IOException {
HttpGet method = new HttpGet(region.getStorageUrl(container, object));
Response response = this.execute(method);
if(response.getStatusCode() == HttpStatus.SC_OK) {
return response.getResponseBodyAsStream();
return response;
}
else if(response.getStatusCode() == HttpStatus.SC_NOT_FOUND) {
method.abort();
Expand All @@ -1495,11 +1494,11 @@ else if(response.getStatusCode() == HttpStatus.SC_NOT_FOUND) {
}
}

public ContentLengthInputStream getObject(Region region, String container, String object, long offset) throws IOException {
public Response getObject(Region region, String container, String object, long offset) throws IOException {
return this.getObject(region, container, object, offset, -1L);
}

public ContentLengthInputStream getObject(Region region, String container, String object, long offset, long length) throws IOException {
public Response getObject(Region region, String container, String object, long offset, long length) throws IOException {
HttpGet method = new HttpGet(region.getStorageUrl(container, object));
if(length > 0) {
method.setHeader(HttpHeaders.RANGE, String.format("bytes=%d-%d", offset, offset + length));
Expand All @@ -1509,7 +1508,7 @@ public ContentLengthInputStream getObject(Region region, String container, Strin
}
Response response = this.execute(method);
if(response.getStatusCode() == HttpStatus.SC_PARTIAL_CONTENT) {
return response.getResponseBodyAsStream();
return response;
}
else if(response.getStatusCode() == HttpStatus.SC_NOT_FOUND) {
method.abort();
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/ch/iterate/openstack/swift/Response.java
Expand Up @@ -57,6 +57,10 @@ public String getStatusMessage() {
return response.getStatusLine().getReasonPhrase();
}

public HttpResponse getResponse() {
return response;
}

/**
* Returns the response body as text
*
Expand Down

0 comments on commit 1899392

Please sign in to comment.