fix #2015 add api.*.response.headers
This commit is contained in:
parent
3a83511454
commit
0643349425
8 changed files with 168 additions and 1 deletions
|
@ -86,7 +86,7 @@ public abstract class BaseApiManager implements WebApiManager {
|
|||
return formatType;
|
||||
}
|
||||
|
||||
public static void write(final String text, final String contentType, final String encoding) {
|
||||
protected void write(final String text, final String contentType, final String encoding) {
|
||||
final StringBuilder buf = new StringBuilder(50);
|
||||
if (contentType == null) {
|
||||
buf.append("text/plain");
|
||||
|
@ -107,10 +107,13 @@ public abstract class BaseApiManager implements WebApiManager {
|
|||
buf.append(enc);
|
||||
final HttpServletResponse response = LaResponseUtil.getResponse();
|
||||
response.setContentType(buf.toString());
|
||||
writeHeaders(response);
|
||||
try (PrintWriter out = new PrintWriter(new OutputStreamWriter(response.getOutputStream(), enc))) {
|
||||
out.print(text);
|
||||
} catch (final IOException e) {
|
||||
throw new IORuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract void writeHeaders(final HttpServletResponse response);
|
||||
}
|
|
@ -152,6 +152,7 @@ public class EsApiManager extends BaseApiManager {
|
|||
|
||||
try (ServletOutputStream out = response.getOutputStream(); InputStream in = curlResponse.getContentAsStream()) {
|
||||
response.setStatus(curlResponse.getHttpStatusCode());
|
||||
writeHeaders(response);
|
||||
CopyUtil.copy(in, out);
|
||||
} catch (final ClientAbortException e) {
|
||||
logger.debug("Client aborts this request.", e);
|
||||
|
@ -173,6 +174,7 @@ public class EsApiManager extends BaseApiManager {
|
|||
if (Files.exists(filePath)) {
|
||||
try (InputStream in = Files.newInputStream(filePath); ServletOutputStream out = response.getOutputStream()) {
|
||||
response.setStatus(HttpServletResponse.SC_OK);
|
||||
writeHeaders(response);
|
||||
CopyUtil.copy(in, out);
|
||||
} catch (final ClientAbortException e) {
|
||||
logger.debug("Client aborts this request.", e);
|
||||
|
@ -182,6 +184,7 @@ public class EsApiManager extends BaseApiManager {
|
|||
}
|
||||
} else {
|
||||
try {
|
||||
writeHeaders(response);
|
||||
response.sendError(HttpServletResponse.SC_NOT_FOUND, path + " is not found.");
|
||||
} catch (final ClientAbortException e) {
|
||||
logger.debug("Client aborts this request.", e);
|
||||
|
@ -208,4 +211,9 @@ public class EsApiManager extends BaseApiManager {
|
|||
private SessionManager getSessionManager() {
|
||||
return ComponentUtil.getComponent(SessionManager.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeHeaders(HttpServletResponse response) {
|
||||
ComponentUtil.getFessConfig().getApiDashboardResponseHeaderList().forEach(e -> response.setHeader(e.getFirst(), e.getSecond()));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -644,4 +644,9 @@ public class GsaApiManager extends BaseApiManager implements WebApiManager {
|
|||
public void setContentTypeField(final String contentTypeField) {
|
||||
this.contentTypeField = contentTypeField;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeHeaders(HttpServletResponse response) {
|
||||
ComponentUtil.getFessConfig().getApiGsaResponseHeaderList().forEach(e -> response.setHeader(e.getFirst(), e.getSecond()));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -812,4 +812,9 @@ public class JsonApiManager extends BaseJsonApiManager {
|
|||
return ComponentUtil.getViewHelper().createHighlightInfo();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeHeaders(HttpServletResponse response) {
|
||||
ComponentUtil.getFessConfig().getApiJsonResponseHeaderList().forEach(e -> response.setHeader(e.getFirst(), e.getSecond()));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -300,4 +300,9 @@ public class SuggestApiManager extends BaseJsonApiManager {
|
|||
return new HighlightInfo();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeHeaders(HttpServletResponse response) {
|
||||
ComponentUtil.getFessConfig().getApiJsonResponseHeaderList().forEach(e -> response.setHeader(e.getFirst(), e.getSecond()));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -190,6 +190,15 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction
|
|||
/** The key of the configuration. e.g. false */
|
||||
String API_SEARCH_SCROLL = "api.search.scroll";
|
||||
|
||||
/** The key of the configuration. e.g. */
|
||||
String API_JSON_RESPONSE_HEADERS = "api.json.response.headers";
|
||||
|
||||
/** The key of the configuration. e.g. */
|
||||
String API_GSA_RESPONSE_HEADERS = "api.gsa.response.headers";
|
||||
|
||||
/** The key of the configuration. e.g. */
|
||||
String API_DASHBOARD_RESPONSE_HEADERS = "api.dashboard.response.headers";
|
||||
|
||||
/** The key of the configuration. e.g. */
|
||||
String VIRTUAL_HOST_HEADERS = "virtual.host.headers";
|
||||
|
||||
|
@ -1793,6 +1802,51 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction
|
|||
*/
|
||||
boolean isApiSearchScroll();
|
||||
|
||||
/**
|
||||
* Get the value for the key 'api.json.response.headers'. <br>
|
||||
* The value is, e.g. <br>
|
||||
* @return The value of found property. (NotNull: if not found, exception but basically no way)
|
||||
*/
|
||||
String getApiJsonResponseHeaders();
|
||||
|
||||
/**
|
||||
* Get the value for the key 'api.json.response.headers' as {@link Integer}. <br>
|
||||
* The value is, e.g. <br>
|
||||
* @return The value of found property. (NotNull: if not found, exception but basically no way)
|
||||
* @throws NumberFormatException When the property is not integer.
|
||||
*/
|
||||
Integer getApiJsonResponseHeadersAsInteger();
|
||||
|
||||
/**
|
||||
* Get the value for the key 'api.gsa.response.headers'. <br>
|
||||
* The value is, e.g. <br>
|
||||
* @return The value of found property. (NotNull: if not found, exception but basically no way)
|
||||
*/
|
||||
String getApiGsaResponseHeaders();
|
||||
|
||||
/**
|
||||
* Get the value for the key 'api.gsa.response.headers' as {@link Integer}. <br>
|
||||
* The value is, e.g. <br>
|
||||
* @return The value of found property. (NotNull: if not found, exception but basically no way)
|
||||
* @throws NumberFormatException When the property is not integer.
|
||||
*/
|
||||
Integer getApiGsaResponseHeadersAsInteger();
|
||||
|
||||
/**
|
||||
* Get the value for the key 'api.dashboard.response.headers'. <br>
|
||||
* The value is, e.g. <br>
|
||||
* @return The value of found property. (NotNull: if not found, exception but basically no way)
|
||||
*/
|
||||
String getApiDashboardResponseHeaders();
|
||||
|
||||
/**
|
||||
* Get the value for the key 'api.dashboard.response.headers' as {@link Integer}. <br>
|
||||
* The value is, e.g. <br>
|
||||
* @return The value of found property. (NotNull: if not found, exception but basically no way)
|
||||
* @throws NumberFormatException When the property is not integer.
|
||||
*/
|
||||
Integer getApiDashboardResponseHeadersAsInteger();
|
||||
|
||||
/**
|
||||
* Get the value for the key 'virtual.host.headers'. <br>
|
||||
* The value is, e.g. <br>
|
||||
|
@ -6124,6 +6178,30 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction
|
|||
return is(FessConfig.API_SEARCH_SCROLL);
|
||||
}
|
||||
|
||||
public String getApiJsonResponseHeaders() {
|
||||
return get(FessConfig.API_JSON_RESPONSE_HEADERS);
|
||||
}
|
||||
|
||||
public Integer getApiJsonResponseHeadersAsInteger() {
|
||||
return getAsInteger(FessConfig.API_JSON_RESPONSE_HEADERS);
|
||||
}
|
||||
|
||||
public String getApiGsaResponseHeaders() {
|
||||
return get(FessConfig.API_GSA_RESPONSE_HEADERS);
|
||||
}
|
||||
|
||||
public Integer getApiGsaResponseHeadersAsInteger() {
|
||||
return getAsInteger(FessConfig.API_GSA_RESPONSE_HEADERS);
|
||||
}
|
||||
|
||||
public String getApiDashboardResponseHeaders() {
|
||||
return get(FessConfig.API_DASHBOARD_RESPONSE_HEADERS);
|
||||
}
|
||||
|
||||
public Integer getApiDashboardResponseHeadersAsInteger() {
|
||||
return getAsInteger(FessConfig.API_DASHBOARD_RESPONSE_HEADERS);
|
||||
}
|
||||
|
||||
public String getVirtualHostHeaders() {
|
||||
return get(FessConfig.VIRTUAL_HOST_HEADERS);
|
||||
}
|
||||
|
@ -8410,6 +8488,9 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction
|
|||
defaultMap.put(FessConfig.API_ADMIN_ACCESS_PERMISSIONS, "Radmin-api");
|
||||
defaultMap.put(FessConfig.API_SEARCH_ACCEPT_REFERERS, "");
|
||||
defaultMap.put(FessConfig.API_SEARCH_SCROLL, "false");
|
||||
defaultMap.put(FessConfig.API_JSON_RESPONSE_HEADERS, "");
|
||||
defaultMap.put(FessConfig.API_GSA_RESPONSE_HEADERS, "");
|
||||
defaultMap.put(FessConfig.API_DASHBOARD_RESPONSE_HEADERS, "");
|
||||
defaultMap.put(FessConfig.VIRTUAL_HOST_HEADERS, "");
|
||||
defaultMap.put(FessConfig.HTTP_PROXY_HOST, "");
|
||||
defaultMap.put(FessConfig.HTTP_PROXY_PORT, "8080");
|
||||
|
|
|
@ -70,6 +70,12 @@ import org.lastaflute.web.validation.theme.typed.LongTypeValidator;
|
|||
|
||||
public interface FessProp {
|
||||
|
||||
String API_DASHBOARD_RESPONSE_HEADER_LIST = "apiDashboardResponseHeaderList";
|
||||
|
||||
String API_JSON_RESPONSE_HEADER_LIST = "apiJsonResponseHeaderList";
|
||||
|
||||
String API_GSA_RESPONSE_HEADER_LIST = "apiGsaResponseHeaderList";
|
||||
|
||||
String SMB_AVAILABLE_SID_TYPES = "smbAvailableSidTypes";
|
||||
|
||||
String LOGGING_SEARCH_DOCS_FIELDS = "loggingSearchDocsFields";
|
||||
|
@ -1912,4 +1918,55 @@ public interface FessProp {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
String getApiGsaResponseHeaders();
|
||||
|
||||
default List<Pair<String, String>> getApiGsaResponseHeaderList() {
|
||||
List<Pair<String, String>> list = (List<Pair<String, String>>) propMap.get(API_GSA_RESPONSE_HEADER_LIST);
|
||||
if (list == null) {
|
||||
list = split(getApiGsaResponseHeaders(), "\n").get(stream -> stream.filter(StringUtil::isNotBlank).map(s -> {
|
||||
String[] values = s.split(":", 2);
|
||||
if (values.length == 2) {
|
||||
return new Pair<>(values[0], values[1]);
|
||||
}
|
||||
return new Pair<>(values[0], StringUtil.EMPTY);
|
||||
}).collect(Collectors.toList()));
|
||||
propMap.put(API_GSA_RESPONSE_HEADER_LIST, list);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
String getApiJsonResponseHeaders();
|
||||
|
||||
default List<Pair<String, String>> getApiJsonResponseHeaderList() {
|
||||
List<Pair<String, String>> list = (List<Pair<String, String>>) propMap.get(API_JSON_RESPONSE_HEADER_LIST);
|
||||
if (list == null) {
|
||||
list = split(getApiJsonResponseHeaders(), "\n").get(stream -> stream.filter(StringUtil::isNotBlank).map(s -> {
|
||||
String[] values = s.split(":", 2);
|
||||
if (values.length == 2) {
|
||||
return new Pair<>(values[0], values[1]);
|
||||
}
|
||||
return new Pair<>(values[0], StringUtil.EMPTY);
|
||||
}).collect(Collectors.toList()));
|
||||
propMap.put(API_JSON_RESPONSE_HEADER_LIST, list);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
String getApiDashboardResponseHeaders();
|
||||
|
||||
default List<Pair<String, String>> getApiDashboardResponseHeaderList() {
|
||||
List<Pair<String, String>> list = (List<Pair<String, String>>) propMap.get(API_DASHBOARD_RESPONSE_HEADER_LIST);
|
||||
if (list == null) {
|
||||
list = split(getApiDashboardResponseHeaders(), "\n").get(stream -> stream.filter(StringUtil::isNotBlank).map(s -> {
|
||||
String[] values = s.split(":", 2);
|
||||
if (values.length == 2) {
|
||||
return new Pair<>(values[0], values[1]);
|
||||
}
|
||||
return new Pair<>(values[0], StringUtil.EMPTY);
|
||||
}).collect(Collectors.toList()));
|
||||
propMap.put(API_DASHBOARD_RESPONSE_HEADER_LIST, list);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -133,6 +133,9 @@ api.access.token.request.parameter=
|
|||
api.admin.access.permissions=Radmin-api
|
||||
api.search.accept.referers=
|
||||
api.search.scroll=false
|
||||
api.json.response.headers=
|
||||
api.gsa.response.headers=
|
||||
api.dashboard.response.headers=
|
||||
|
||||
# Virtual Host: Host:fess.codelibs.org=fess
|
||||
virtual.host.headers=
|
||||
|
|
Loading…
Add table
Reference in a new issue