简体   繁体   中英

Undertow filter to set request header like mod_headers?

My live server is using mod_headers to set a value with a syntax like -

Header set MY_FILE "MY_VALUE"

Is there an undertow filter to set a value in a request header prior to passing to my application?

<subsystem>
   <filters>
      <response-header name="server-header" header-name="Server" header-value="WildFly/8"/>
      <response-header name="x-powered-by-header" header-name="X-Powered-By" header-value="Undertow/1"/>
   </filters>
</subsystem>

The reason for my question is that I am needing to connect automate my selenium tests on Jenkins, and cant set the value without changing the configuration of my application. My Jenkins environment is not fronted with Apache

Use the expression-filter filter.

<host name="default-host" alias="localhost">
    ...
    <filter-ref name="set-custom-header"/>
    ...
    ...
</host>


<filters>
    ...
    ...
    <expression-filter name="set-custom-header" expression="set(attribute='%{i,MY_FILE}', value='MY_VALUE')"/>
</filters>

documentation:

http://undertow.io/undertow-docs/undertow-docs-1.3.0/predicates-attributes-handlers.html

The attribute %{i,request_header_name} defines request attribute.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM