Add Cache-Control and Pragma Header (#18406)

* Add Cache Control and Pragma to Asset Servlet

* Add on null Or Empty
This commit is contained in:
Mohit Yadav 2024-10-28 15:42:37 +05:30 committed by GitHub
parent f45c5ddf5e
commit 35d1053dc0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,5 +1,7 @@
package org.openmetadata.service.exception;
import static org.openmetadata.common.utils.CommonUtil.nullOrEmpty;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
@ -13,6 +15,8 @@ import org.openmetadata.service.config.OMWebConfiguration;
@Slf4j
public class OMErrorPageHandler extends ErrorPageErrorHandler {
private static final String CACHE_CONTROL_HEADER = "Cache-Control";
private static final String PRAGMA_HEADER = "Pragma";
private final OMWebConfiguration webConfiguration;
public OMErrorPageHandler(OMWebConfiguration webConfiguration) {
@ -88,6 +92,16 @@ public class OMErrorPageHandler extends ErrorPageErrorHandler {
// Policy Permission
webConfiguration.getPermissionPolicyHeaderFactory().build().forEach(response::setHeader);
// Cache-Control
if (!nullOrEmpty(webConfiguration.getCacheControl())) {
response.setHeader(CACHE_CONTROL_HEADER, webConfiguration.getCacheControl());
}
// Pragma
if (!nullOrEmpty(webConfiguration.getPragma())) {
response.setHeader(PRAGMA_HEADER, webConfiguration.getPragma());
}
// Additional Headers
webConfiguration.getHeaders().forEach(response::setHeader);
}