From 3a81693d12fd1a48615ec9baade9dc0ac207d25c Mon Sep 17 00:00:00 2001 From: Ronald Brill Date: Fri, 6 Oct 2023 17:55:56 +0200 Subject: [PATCH] sending the correct content type of "application/pdf" for PDF files for form-multipart posts --- src/changes/changes.xml | 3 +++ src/main/java/org/htmlunit/BrowserVersion.java | 4 ++++ .../java/org/htmlunit/html/HtmlFileInput3Test.java | 10 ++++++++++ 3 files changed, 17 insertions(+) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 3acbb80af96..02fa2e25a33 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -8,6 +8,9 @@ + + Sending the correct content type of "application/pdf" for PDF files for form-multipart posts. + Fixed a major leak - frame windows (incl. iframes) are still referenced by the web client windows list after the parent was closed. In the end they are not garbage collected. diff --git a/src/main/java/org/htmlunit/BrowserVersion.java b/src/main/java/org/htmlunit/BrowserVersion.java index 3f03f5a5acb..37a10a30aa5 100644 --- a/src/main/java/org/htmlunit/BrowserVersion.java +++ b/src/main/java/org/htmlunit/BrowserVersion.java @@ -319,6 +319,7 @@ public final class BrowserVersion implements Serializable { CHROME.registerUploadMimeType("jpeg", MimeType.IMAGE_JPEG); CHROME.registerUploadMimeType("jpg", MimeType.IMAGE_JPEG); CHROME.registerUploadMimeType("png", MimeType.IMAGE_PNG); + CHROME.registerUploadMimeType("pdf", "application/pdf"); CHROME.registerUploadMimeType("webp", "image/webp"); CHROME.registerUploadMimeType("mp4", "video/mp4"); CHROME.registerUploadMimeType("m4v", "video/mp4"); @@ -346,6 +347,7 @@ public final class BrowserVersion implements Serializable { EDGE.registerUploadMimeType("jpeg", MimeType.IMAGE_JPEG); EDGE.registerUploadMimeType("jpg", MimeType.IMAGE_JPEG); EDGE.registerUploadMimeType("png", MimeType.IMAGE_PNG); + EDGE.registerUploadMimeType("pdf", "application/pdf"); EDGE.registerUploadMimeType("webp", "image/webp"); EDGE.registerUploadMimeType("mp4", "video/mp4"); EDGE.registerUploadMimeType("m4v", "video/mp4"); @@ -372,6 +374,7 @@ public final class BrowserVersion implements Serializable { FIREFOX_ESR.registerUploadMimeType("gif", MimeType.IMAGE_GIF); FIREFOX_ESR.registerUploadMimeType("jpeg", MimeType.IMAGE_JPEG); FIREFOX_ESR.registerUploadMimeType("jpg", MimeType.IMAGE_JPEG); + FIREFOX_ESR.registerUploadMimeType("pdf", "application/pdf"); FIREFOX_ESR.registerUploadMimeType("mp4", "video/mp4"); FIREFOX_ESR.registerUploadMimeType("m4v", "video/mp4"); FIREFOX_ESR.registerUploadMimeType("m4a", "audio/mp4"); @@ -398,6 +401,7 @@ public final class BrowserVersion implements Serializable { FIREFOX.registerUploadMimeType("gif", MimeType.IMAGE_GIF); FIREFOX.registerUploadMimeType("jpeg", MimeType.IMAGE_JPEG); FIREFOX.registerUploadMimeType("jpg", MimeType.IMAGE_JPEG); + FIREFOX.registerUploadMimeType("pdf", "application/pdf"); FIREFOX.registerUploadMimeType("mp4", "video/mp4"); FIREFOX.registerUploadMimeType("m4v", "video/mp4"); FIREFOX.registerUploadMimeType("m4a", "audio/mp4"); diff --git a/src/test/java/org/htmlunit/html/HtmlFileInput3Test.java b/src/test/java/org/htmlunit/html/HtmlFileInput3Test.java index b22871f4a55..1f289e490e9 100644 --- a/src/test/java/org/htmlunit/html/HtmlFileInput3Test.java +++ b/src/test/java/org/htmlunit/html/HtmlFileInput3Test.java @@ -239,6 +239,16 @@ public void contentTypeWebm() throws Exception { contentType("webm"); } + /** + * @throws Exception if an error occurs + */ + @Test + @Alerts(DEFAULT = {"CONTENT_TYPE:application/pdf", "charset"}, + IE = {"CONTENT_TYPE:application/octet-stream", "charset"}) + public void contentTypePdf() throws Exception { + contentType("pdf"); + } + /** * @throws Exception if an error occurs */