...
response.http.headers.config
Comma separated header config in format [action] [header]:[value]
Type: LISTComma separated list
Valid Values: Values must use same format as headerConfig defined in https://www.eclipse.org/jetty/javadoc/9.4.24.v20191120/org/eclipse/jetty/servlets/HeaderFilter.htmlJetty's HeaderFilter documentation:
Code Block |
---|
[action] [header name]: [header value] |
...
[action]
can be one of "set
, add
, setDate
, or addDate
" which which specify an action will perform on header.
set
action is same as setHeader function in HttpServletResponse, it will set a response header with the given name and value. If the header had already been set, the new value overwrites the previous one.add
action is same as addHeader function in HttpServletResponse, it will add a new value to the header. Responses headers could have multiple values.setDate
action is same as setDateHeader function in HttpServletResponse. It will set HTTP header need date value. Such as "setDate Expires: 31540000000
" which which indicates the header will be expired approximately one year in the future.addDate
action is same as addDateHeader function in HttpServletResponse. It will add a response header with the given name and date-value. Such as "addDate Last-Modified: 0
" which indicates the Last-Modified date is same as current system date.
[header name]
name of header defined in (For examples, see: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers)
[header value]
value for the header defined in https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers We need put double quotes around the value if the value contains commas due to we use comma as separator for different headers. Default Value: ""
Example:
...
Since we're using Jetty to serve this, we can take advantage of the Jetty HeaderFilter class to allow the configuration of these headers. We add configuration property response.http.headers.config
in the org.apache.kafka.connect.runtime.WorkerConfig
class and update org.apache.kafka.connect.runtime.rest.RestServer class. During initialization process, REST server will read all header configurations from the property response.http.headers.config
, and create a FilterHolder with HeaderFilter class and add the filter holder to the Servlet context handler. We only need to provide a single HeaderFilter for the entire server, because that HeaderFilter can set as many headers as the customer needs. Both set
and add
action will add a header and value to the response header if the header is not already in the response. When the header is there, set
action overwrites the existing value, whereas add
action adds an additional value to the header value. So it is customerthe Kafka user's applications and server administrator responsibility to manage headers configured and existing headers.
...
- REST application load configuration file
- Application parse the property "
response.http.headers.config
" in configuration file in configuration file using RestConfig if application based on rest-utils or using WorkerConfig if application is Kafka Connect - Application create FilterHolder with HeadFilter class.
- Application ServletContextHandler add the HeadFilter
...
Supporting other optional parameters, that are responseare response.http.headers.included.paths
, response.http.headers.included.mime.types
, response response.http.headers.included.methods
, response response.http.headers.excluded.paths
, response.http.headers.excluded.mime.types
, response.http.headers.excluded.methods
, don't add value based on existing customer complain about missing header in HTTP response headers. Customer will be happy as long as the headers they want in HTTP response header. This will simply configuration properties lot. We could easily add these optional parameters if customer need it in the future. Any response headers set with response.http.headers.config will be overridden by the application
Another option would be to try to determine what the right headers are in all cases, and always send them. This is appealing because it would not require any end-user customization. However new security headers are regularly added by the web development community, and it would be difficult for us to anticipate all of our users' needs. By providing a configurable option, users can implement the headers that make sense in their own security environments.