From e35c04d8c6b9e4ef264e5ff65f1c03e80a25fdf6 Mon Sep 17 00:00:00 2001 From: Shinsuke Sugaya Date: Sun, 19 Nov 2023 11:22:47 +0900 Subject: [PATCH] fix #2784 Added functionality to set Content-Disposition to inline based on MIME types configuration --- .../java/org/codelibs/fess/helper/ViewHelper.java | 6 ++++-- .../fess/mylasta/direction/FessConfig.java | 15 +++++++++++++++ src/main/resources/app.xml | 3 --- src/main/resources/fess_config.properties | 1 + 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/codelibs/fess/helper/ViewHelper.java b/src/main/java/org/codelibs/fess/helper/ViewHelper.java index 29e909957..8a38210f2 100644 --- a/src/main/java/org/codelibs/fess/helper/ViewHelper.java +++ b/src/main/java/org/codelibs/fess/helper/ViewHelper.java @@ -83,7 +83,6 @@ import org.lastaflute.web.response.StreamResponse; import org.lastaflute.web.ruts.process.ActionRuntime; import org.lastaflute.web.util.LaRequestUtil; -import org.lastaflute.web.util.LaResponseUtil; import org.lastaflute.web.util.LaServletContextUtil; import org.opensearch.core.common.text.Text; import org.opensearch.search.fetch.subphase.highlight.HighlightField; @@ -211,6 +210,9 @@ public void init() { textFragmentPrefixLength = fessConfig.getQueryHighlightTextFragmentPrefixLengthAsInteger(); textFragmentSuffixLength = fessConfig.getQueryHighlightTextFragmentSuffixLengthAsInteger(); textFragmentSize = fessConfig.getQueryHighlightTextFragmentSizeAsInteger(); + + split(fessConfig.getResponseInlineMimetypes(), ",") + .of(stream -> stream.map(String::trim).filter(StringUtil::isNotEmpty).forEach(inlineMimeTypeSet::add)); } public String getContentTitle(final Map document) { @@ -759,7 +761,7 @@ protected void writeContentType(final StreamResponse response, final ResponseDat return; } if (mimeType.startsWith("text/")) { - final String charset = LaResponseUtil.getResponse().getCharacterEncoding(); + final String charset = responseData.getCharSet(); if (charset != null) { response.contentType(mimeType + "; charset=" + charset); return; diff --git a/src/main/java/org/codelibs/fess/mylasta/direction/FessConfig.java b/src/main/java/org/codelibs/fess/mylasta/direction/FessConfig.java index f04be0aa8..0a55c5b50 100644 --- a/src/main/java/org/codelibs/fess/mylasta/direction/FessConfig.java +++ b/src/main/java/org/codelibs/fess/mylasta/direction/FessConfig.java @@ -673,6 +673,9 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction /** The key of the configuration. e.g. true */ String RESPONSE_HIGHLIGHT_content_title_ENABLED = "response.highlight.content_title.enabled"; + /** The key of the configuration. e.g. application/pdf,text/plain */ + String RESPONSE_INLINE_MIMETYPES = "response.inline.mimetypes"; + /** The key of the configuration. e.g. fess.search */ String INDEX_DOCUMENT_SEARCH_INDEX = "index.document.search.index"; @@ -3881,6 +3884,13 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction */ boolean isResponseHighlightContentTitleEnabled(); + /** + * Get the value for the key 'response.inline.mimetypes'.
+ * The value is, e.g. application/pdf,text/plain
+ * @return The value of found property. (NotNull: if not found, exception but basically no way) + */ + String getResponseInlineMimetypes(); + /** * Get the value for the key 'index.document.search.index'.
* The value is, e.g. fess.search
@@ -8774,6 +8784,10 @@ public boolean isResponseHighlightContentTitleEnabled() { return is(FessConfig.RESPONSE_HIGHLIGHT_content_title_ENABLED); } + public String getResponseInlineMimetypes() { + return get(FessConfig.RESPONSE_INLINE_MIMETYPES); + } + public String getIndexDocumentSearchIndex() { return get(FessConfig.INDEX_DOCUMENT_SEARCH_INDEX); } @@ -10990,6 +11004,7 @@ protected java.util.Map prepareGeneratedDefaultMap() { defaultMap.put(FessConfig.RESPONSE_MAX_TITLE_LENGTH, "50"); defaultMap.put(FessConfig.RESPONSE_MAX_SITE_PATH_LENGTH, "100"); defaultMap.put(FessConfig.RESPONSE_HIGHLIGHT_content_title_ENABLED, "true"); + defaultMap.put(FessConfig.RESPONSE_INLINE_MIMETYPES, "application/pdf,text/plain"); defaultMap.put(FessConfig.INDEX_DOCUMENT_SEARCH_INDEX, "fess.search"); defaultMap.put(FessConfig.INDEX_DOCUMENT_UPDATE_INDEX, "fess.update"); defaultMap.put(FessConfig.INDEX_DOCUMENT_SUGGEST_INDEX, "fess"); diff --git a/src/main/resources/app.xml b/src/main/resources/app.xml index f3c244d36..0591be0ea 100644 --- a/src/main/resources/app.xml +++ b/src/main/resources/app.xml @@ -56,9 +56,6 @@ - - "application/pdf" - diff --git a/src/main/resources/fess_config.properties b/src/main/resources/fess_config.properties index f4539d830..f3f35aca0 100644 --- a/src/main/resources/fess_config.properties +++ b/src/main/resources/fess_config.properties @@ -337,6 +337,7 @@ response.field.site_path=site_path response.max.title.length=50 response.max.site.path.length=100 response.highlight.content_title.enabled=true +response.inline.mimetypes=application/pdf,text/plain # document index index.document.search.index=fess.search