Skip to content

Commit

Permalink
webdav user agent, binary response for binary files
Browse files Browse the repository at this point in the history
  • Loading branch information
lgajos committed Sep 30, 2020
1 parent 8abd059 commit 6e696b0
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/main/java/notepack/app/storage/Webdav.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ public byte[] loadContent(String path) throws MessageError {
try {

HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(path)).GET().build();
.uri(URI.create(path)).setHeader("User-Agent", "Notepack WebDAV").GET().build();

HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
HttpResponse<byte[]> response = client.send(request, HttpResponse.BodyHandlers.ofByteArray());

return response.body().getBytes();
return response.body();

} catch (IOException | InterruptedException ex) {
throw new MessageError(ex.getMessage(), ex);
Expand Down Expand Up @@ -125,7 +125,7 @@ private NoteStorageItem addItems(NoteStorageItem parent, String startPath, int d
} catch (URISyntaxException ex) {
Logger.getLogger(Webdav.class.getName()).log(Level.SEVERE, null, ex);
}

ArrayList<String> supportedExtensions = Render.getSupportedExtensions();

try {
Expand All @@ -136,7 +136,7 @@ private NoteStorageItem addItems(NoteStorageItem parent, String startPath, int d
+ "</D:propfind>";

HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(startPath)).header("Depth", "1").method("PROPFIND", BodyPublishers.ofString(propfind)).build();
.uri(URI.create(startPath)).setHeader("User-Agent", "Notepack WebDAV").header("Depth", "1").method("PROPFIND", BodyPublishers.ofString(propfind)).build();

HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());

Expand Down Expand Up @@ -186,7 +186,10 @@ private NoteStorageItem addItems(NoteStorageItem parent, String startPath, int d
}
long getcontentlength = 0;
if (eElement.getElementsByTagNameNS("DAV:", "getcontentlength").getLength() > 0) {
getcontentlength = Long.parseLong(eElement.getElementsByTagNameNS("DAV:", "getcontentlength").item(0).getTextContent());
String contentLength = eElement.getElementsByTagNameNS("DAV:", "getcontentlength").item(0).getTextContent();
if (contentLength.length() > 0) {
getcontentlength = Long.parseLong(contentLength);
}
}

String tmp = URLDecoder.decode(path, "UTF-8");
Expand Down

0 comments on commit 6e696b0

Please sign in to comment.