Skip to content

add cross origin config:max.age,allow.headers #111

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions core/src/main/java/io/confluent/rest/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,15 @@ protected void doStop() throws Exception {
if (allowedMethods != null && !allowedOrigins.trim().isEmpty()) {
filterHolder.setInitParameter(CrossOriginFilter.ALLOWED_METHODS_PARAM, allowedMethods);
}
String controlMaxAge = getConfiguration().getString(RestConfig.ACCESS_CONTROL_MAX_AGE);
if (controlMaxAge != null && !controlMaxAge.trim().isEmpty()) {
filterHolder.setInitParameter(CrossOriginFilter.PREFLIGHT_MAX_AGE_PARAM, controlMaxAge);
}
String allowedHeaders = getConfiguration().getString(RestConfig.ACCESS_CONTROL_ALLOW_HEADERS);
if (allowedHeaders != null && !allowedHeaders.trim().isEmpty()) {
filterHolder.setInitParameter(CrossOriginFilter.ALLOWED_HEADERS_PARAM, allowedHeaders);
}

context.addFilter(filterHolder, "/*", EnumSet.of(DispatcherType.REQUEST));
}
configurePreResourceHandling(context);
Expand Down
22 changes: 22 additions & 0 deletions core/src/main/java/io/confluent/rest/RestConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,16 @@ public class RestConfig extends AbstractConfig {
"Set value to Jetty Access-Control-Allow-Origin header for specified methods";
protected static final String ACCESS_CONTROL_ALLOW_METHODS_DEFAULT = "";

public static final String ACCESS_CONTROL_ALLOW_HEADERS = "access.control.allow.headers";
protected static final String ACCESS_CONTROL_ALLOW_HEADERS_DOC =
"Set value to Jetty Access-Control-Allow-Headers header for specified methods";
protected static final String ACCESS_CONTROL_ALLOW_HEADERS_DEFAULT = "";

public static final String ACCESS_CONTROL_MAX_AGE = "access.control.max.age";
protected static final String ACCESS_CONTROL_MAX_AGE_DOC =
"Set value to Jetty Access-Control-Max-Age header for specified methods";
protected static final String ACCESS_CONTROL_MAX_AGE_DEFAULT = "";


public static final String REQUEST_LOGGER_NAME_CONFIG = "request.logger.name";
protected static final String REQUEST_LOGGER_NAME_DOC =
Expand Down Expand Up @@ -265,6 +275,18 @@ public static ConfigDef baseConfigDef() {
ACCESS_CONTROL_ALLOW_METHODS_DEFAULT,
Importance.LOW,
ACCESS_CONTROL_ALLOW_METHODS_DOC
).define(
ACCESS_CONTROL_ALLOW_HEADERS,
Type.STRING,
ACCESS_CONTROL_ALLOW_HEADERS_DEFAULT,
Importance.LOW,
ACCESS_CONTROL_ALLOW_HEADERS_DOC
).define(
ACCESS_CONTROL_MAX_AGE,
Type.LONG,
ACCESS_CONTROL_MAX_AGE_DEFAULT,
Importance.LOW,
ACCESS_CONTROL_MAX_AGE_DOC
).define(
REQUEST_LOGGER_NAME_CONFIG,
Type.STRING,
Expand Down