You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Thomas Meyer <th...@m3y3r.de> on 2019/03/13 09:43:13 UTC

How to add an header field to all requests unconditionally

Hi,

what would be the easiest way to uncoditionally add an header field to  
all requests coming from a given connector?
I searched the provided Valves but there seems to be no support for my  
requirment.

with kind regards
thomas




---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: How to add an header field to all requests unconditionally

Posted by Jäkel, Guido <G....@dnb.de>.
>-----Original Message-----
>From: André Warnier (tomcat) [mailto:aw@ice-sa.com]
>Sent: Wednesday, March 13, 2019 12:11 PM
>To: users@tomcat.apache.org
>Subject: Re: How to add an header field to all requests unconditionally
>
>The OP wants to insert a *Request* header, not a Response header.
>As I recall, that is a bit more complicated, because under Tomcat the Request is
>immutable, so you have to subclass it, and add the header dynamically when the application
>issues a request.getHeaders call or so.

Oh sorry, I misinterpreted that. 

@Thomas: By other words, you want to know something about the destination of your request. To be curious I want to know what the different Connectors are used for? Maybe there's another thing associated with the Connector that is more easy to detect for the application.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: How to add an header field to all requests unconditionally

Posted by "André Warnier (tomcat)" <aw...@ice-sa.com>.
Addendum :

On 13.03.2019 12:03, André Warnier (tomcat) wrote:
> On 13.03.2019 11:44, Jäkel, Guido wrote:
>> Dear Thomas,
>>
>> you may include a filter servlet into the application to modify the response header. A
>> quick search offers e.g.  https://gist.github.com/danlangford/3669475 , which states to
>> implement a generic, configurable Response Header Filter.

The OP wants to insert a *Request* header, not a Response header.
As I recall, that is a bit more complicated, because under Tomcat the Request is 
immutable, so you have to subclass it, and add the header dynamically when the application 
issues a request.getHeaders call or so.

>>
>> You may compile this servlet independent from an existing application, therefore you may
>> tweak even existing WARs with this.
>>
>
> Just a note : "add a header .. to all requests coming from a given connector"
> Does the servlet filter know what the Connector was, through which the request was
> received ? And even if so, the filter would still need some configuration, in order to do
> that only for the Connector in question.
>
> (A httpd front-end would know, because it would be the one forwarding to that Connector
> specifically)
>
>
>
>> Guido
>>
>>> -----Original Message-----
>>> From: Thomas Meyer [mailto:thomas@m3y3r.de]
>>> Sent: Wednesday, March 13, 2019 10:43 AM
>>> To: users@tomcat.apache.org
>>> Subject: How to add an header field to all requests unconditionally
>>>
>>> Hi,
>>>
>>> what would be the easiest way to uncoditionally add an header field to
>>> all requests coming from a given connector?
>>> I searched the provided Valves but there seems to be no support for my
>>> requirment.
>>>
>>> with kind regards
>>> thomas
>>>
>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>>> For additional commands, e-mail: users-help@tomcat.apache.org
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: How to add an header field to all requests unconditionally

Posted by "André Warnier (tomcat)" <aw...@ice-sa.com>.
On 13.03.2019 11:44, Jäkel, Guido wrote:
> Dear Thomas,
>
> you may include a filter servlet into the application to modify the response header. A quick search offers e.g.  https://gist.github.com/danlangford/3669475 , which states to implement a generic, configurable Response Header Filter.
>
> You may compile this servlet independent from an existing application, therefore you may tweak even existing WARs with this.
>

Just a note : "add a header .. to all requests coming from a given connector"
Does the servlet filter know what the Connector was, through which the request was 
received ? And even if so, the filter would still need some configuration, in order to do 
that only for the Connector in question.

(A httpd front-end would know, because it would be the one forwarding to that Connector 
specifically)



> Guido
>
>> -----Original Message-----
>> From: Thomas Meyer [mailto:thomas@m3y3r.de]
>> Sent: Wednesday, March 13, 2019 10:43 AM
>> To: users@tomcat.apache.org
>> Subject: How to add an header field to all requests unconditionally
>>
>> Hi,
>>
>> what would be the easiest way to uncoditionally add an header field to
>> all requests coming from a given connector?
>> I searched the provided Valves but there seems to be no support for my
>> requirment.
>>
>> with kind regards
>> thomas
>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: How to add an header field to all requests unconditionally

Posted by Jäkel, Guido <G....@dnb.de>.
Dear Thomas,

you may include a filter servlet into the application to modify the response header. A quick search offers e.g.  https://gist.github.com/danlangford/3669475 , which states to implement a generic, configurable Response Header Filter.

You may compile this servlet independent from an existing application, therefore you may tweak even existing WARs with this.

Guido

>-----Original Message-----
>From: Thomas Meyer [mailto:thomas@m3y3r.de]
>Sent: Wednesday, March 13, 2019 10:43 AM
>To: users@tomcat.apache.org
>Subject: How to add an header field to all requests unconditionally
>
>Hi,
>
>what would be the easiest way to uncoditionally add an header field to
>all requests coming from a given connector?
>I searched the provided Valves but there seems to be no support for my
>requirment.
>
>with kind regards
>thomas
>
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>For additional commands, e-mail: users-help@tomcat.apache.org


Re: How to add an header field to all requests unconditionally

Posted by "André Warnier (tomcat)" <aw...@ice-sa.com>.
On 13.03.2019 10:43, Thomas Meyer wrote:
> Hi,
>
> what would be the easiest way to uncoditionally add an header field to all requests coming
> from a given connector?

Add (or use your existing) front-end Apache httpd server, with the mod_headers module ?
http://httpd.apache.org/docs/2.4/mod/mod_headers.html

> I searched the provided Valves but there seems to be no support for my requirment.
>
You may want to look at :

http://tuckey.org/urlrewrite/
(I have not checked for your use case, but it does do many things, so maybe that also)

(Note : the first suggestion above may look facetious and overkill.  But it often happens 
that an initial simple requirement turns more complex and demanding over time, and one can 
do so many additional things using an Apache httpd front-end, that you may want to 
consider it anyway).


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org