Skip to content

Commit 0b8d4c9

Browse files
committed
fix: correctly handle redirect for isFile and isDirectory() call for HTTP KVA
Signed-off-by: Caleb Hulbert <cmhulbert@gmail.com>
1 parent fd9b715 commit 0b8d4c9

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

src/main/java/org/janelia/saalfeldlab/n5/HttpKeyValueAccess.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ public boolean exists(final String normalPath) {
158158
public boolean isDirectory(final String normalPath) {
159159

160160
try {
161-
requireValidHttpResponse(getDirectoryPath(normalPath), HEAD, (code, msg,http) -> {
161+
requireValidHttpResponse(getDirectoryPath(normalPath), HEAD, false, (code, msg,http) -> {
162162
final N5Exception cause = validExistsResponse(code, "Error checking directory: " + normalPath, msg, true);
163163
if (code >= 300 && code < 400) {
164164
final String redirectLocation = http.getHeaderField("Location");
@@ -200,7 +200,7 @@ public boolean isFile(final String normalPath) {
200200

201201
/* Files must not end in `/` And Don't accept a redirect to a location ending in `/` */
202202
try {
203-
requireValidHttpResponse(getFilePath(normalPath), HEAD, (code, msg, http) -> {
203+
requireValidHttpResponse(getFilePath(normalPath), HEAD, false, (code, msg, http) -> {
204204
final N5Exception cause = validExistsResponse(code, "Error accessing file: " + normalPath, msg, true);
205205
if (code >= 300 && code < 400) {
206206
final String redirectLocation = http.getHeaderField("Location");
@@ -316,12 +316,17 @@ private HttpURLConnection requireValidHttpResponse(String uri, String method, St
316316
}
317317

318318
private HttpURLConnection requireValidHttpResponse(String uri, String method, TriFunction<Integer, String, HttpURLConnection, N5Exception> filterCode) throws N5Exception {
319+
return requireValidHttpResponse(uri, method, true, filterCode);
320+
}
321+
322+
private HttpURLConnection requireValidHttpResponse(String uri, String method, boolean followRedirects, TriFunction<Integer, String, HttpURLConnection, N5Exception> filterCode) throws N5Exception {
319323

320324
final int code;
321325
final HttpURLConnection http;
322326
final String responseMsg;
323327
try {
324328
http = httpRequest(uri, method);
329+
http.setInstanceFollowRedirects(followRedirects);
325330
code = http.getResponseCode();
326331
responseMsg = http.getResponseMessage();
327332
} catch (IOException e) {

0 commit comments

Comments
 (0)