Skip to content

Commit

Permalink
added an option to disable versioned-path
Browse files Browse the repository at this point in the history
  • Loading branch information
wizzardo committed Oct 24, 2024
1 parent 5779063 commit 8c66094
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/main/java/com/wizzardo/http/FileTreeHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public class FileTreeHandler<T extends FileTreeHandler.HandlerContext> implement
protected String workDirPath;
protected File workDir;
protected boolean showFolder = true;
protected boolean versionedPath = true;
protected final String name;
protected RangeResponseHelper rangeResponseHelper = new RangeResponseHelper();

Expand Down Expand Up @@ -150,6 +151,11 @@ public FileTreeHandler<T> setShowFolder(boolean showFolder) {
return this;
}

public FileTreeHandler<T> setVersionedPath(boolean versionedPath) {
this.versionedPath = versionedPath;
return this;
}

protected String getCanonicalPath(File file) {
return Unchecked.call(file::getCanonicalPath);
}
Expand Down Expand Up @@ -265,7 +271,12 @@ protected String encodeName(String name) {
}

protected String decodePath(String path) {
byte[] bytes = VERSION_PATTERN.matcher(path).replaceAll("").getBytes(StandardCharsets.UTF_8);
byte[] bytes;
if (versionedPath)
bytes = VERSION_PATTERN.matcher(path).replaceAll("").getBytes(StandardCharsets.UTF_8);
else
bytes = path.getBytes(StandardCharsets.UTF_8);

int decodedLength = PercentEncoding.decode(bytes, 0, bytes.length, true);
return new String(bytes, 0, decodedLength, StandardCharsets.UTF_8);
}
Expand Down

0 comments on commit 8c66094

Please sign in to comment.