Skip to content

Commit

Permalink
Update getFilenameFromHeader to return null on exception (including f…
Browse files Browse the repository at this point in the history
…ileUrl.openConnection)
  • Loading branch information
tylerjmchugh committed Nov 8, 2024
1 parent 702b3ae commit 77d5621
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,9 @@ protected int canDownload(ServiceContext context, String metadataUuid, MetadataR
}

protected String getFilenameFromHeader(final URL fileUrl) throws IOException {
HttpURLConnection connection = (HttpURLConnection) fileUrl.openConnection();
HttpURLConnection connection = null;
try {
connection = (HttpURLConnection) fileUrl.openConnection();
connection.setRequestMethod("HEAD");
connection.connect();
String contentDisposition = connection.getHeaderField("Content-Disposition");
Expand All @@ -173,7 +174,9 @@ protected String getFilenameFromHeader(final URL fileUrl) throws IOException {
log.error("Error retrieving resource filename from header", e);
return null;
} finally {
connection.disconnect();
if (connection != null) {
connection.disconnect();
}
}
}

Expand Down

0 comments on commit 77d5621

Please sign in to comment.