Skip to content

Commit

Permalink
filenameFromContentDisposition in FilenameExtractor should not fail i…
Browse files Browse the repository at this point in the history
…f filename cannot be decoded from header
  • Loading branch information
alexstaeding committed Jan 1, 2024
1 parent 972b6d9 commit 359b2e8
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/main/java/me/itzg/helpers/http/FilenameExtractor.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import lombok.extern.slf4j.Slf4j;
import me.itzg.helpers.errors.GenericException;
import org.apache.cxf.attachment.Rfc5987Util;
import org.apache.hc.client5.http.HttpResponseException;
import org.apache.hc.core5.http.ClassicHttpResponse;
Expand All @@ -15,6 +14,7 @@
import org.apache.hc.core5.http.HttpStatus;
import org.apache.hc.core5.http.ProtocolException;
import org.apache.hc.core5.http.io.entity.EntityUtils;
import org.jetbrains.annotations.Nullable;

@Slf4j
public class FilenameExtractor {
Expand All @@ -30,7 +30,7 @@ public FilenameExtractor(LatchingUrisInterceptor interceptor) {
this.interceptor = Objects.requireNonNull(interceptor, "interceptor is required");
}

static String filenameFromContentDisposition(String headerValue) {
static @Nullable String filenameFromContentDisposition(String headerValue) {
if (headerValue == null) {
return null;
}
Expand All @@ -45,7 +45,8 @@ static String filenameFromContentDisposition(String headerValue) {
try {
return Rfc5987Util.decode(m.group(2), m.group(1));
} catch (UnsupportedEncodingException e) {
throw new GenericException("Failed to decode filename* from " + headerValue, e);
log.debug("Failed to decode filename* from {}", headerValue);
return null;
}
}
else {
Expand All @@ -62,7 +63,8 @@ else if (filename != null) {
}
}
else {
throw new GenericException("Unable to determine filename from header: " + headerValue);
log.debug("Unable to determine filename from header: {}", headerValue);
return null;
}
}

Expand Down

0 comments on commit 359b2e8

Please sign in to comment.