You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Jérémie Barthés <j....@oodrive.fr> on 2017/06/26 09:55:25 UTC
Issue between RewriteValve and DefaultServlet
Hi,
I have an issue between org.apache.catalina.valves.rewrite.RewriteValve
and org.apache.catalina.servlets.DefaultServlets
If my request is forwarded by the RewriteValve and then pass into
doDirectoryRedirect in DefaultServlets to be redirected. The hidden
rewritten URI is displayed in the browser.
To test it, try the following example (any tomcat 8, 8.5 or 9)
add RewriteValve in conf/server.xml
<Valve className="org.apache.catalina.valves.rewrite.RewriteValve"/>
add rewriteRule in conf/Catalina/localhost/rewrite.config
RewriteRule ^/iWantThisVisible/(.*)$/examples/$1/
start tomcat
go to following URLs (any internet browser) :
http://localhost:8080/iWantThisVisible/servlets
http://localhost:8080/iWantThisVisible/servlets/
Regards
Jeremie
Re: Issue between RewriteValve and DefaultServlet
Posted by Jérémie Barthés <j....@oodrive.fr>.
"That behaviour is expected."
I really didn't expect that. it took me two weeks, two years ago to understand why i had a redirect and not a forward if my URI last char isn't a '/'
---------------------------------------------------------------
"The way to handle this is to wrap the response and intercept
the call that sets the location header and modify the value before
calling the wrapped response."
we have other service using redirection to work. It's tricky to wrap response then change location headers without disturbing our 302 redirections.
----------------------------------------------------------------
May this method be protected in following versions ?
"Unlikely at this point."
it would really help in our case. We'll study for other solutions anyway
----------------------------------------------------------------
Thanks
Jeremie
Le 26/06/2017 à 14:52, Mark Thomas a écrit :
> On 26/06/17 11:22, Jérémie Barthés wrote:
>> Thank for your fast answer
>>
>> I would like to extend DefaultServlet to override doDirectoryRedirect
>> but the method is private,
>> private void doDirectoryRedirect(HttpServletRequest request,
>> HttpServletResponse response)
>>
>> May this method be protected in following versions ?
> Unlikely at this point.
>
>> i can't change a header on the way out, after server started to answer,
>> can i ?
> Correct. The way to handle this is to wrap the response and intercept
> the call that sets the location header and modify the value before
> calling the wrapped response.
>
> Mark
>
>
>> Regard
>>
>> Jeremie
>>
>> PS : i added a custom valve just to put non-rewritten URI in a request
>> attribute, so i can use it if present when doDirectoryRedirect occurs
>>
>>
>> Le 26/06/2017 à 12:01, Mark Thomas a écrit :
>>> On 26/06/17 10:55, Jérémie Barthés wrote:
>>>> Hi,
>>>>
>>>> I have an issue between org.apache.catalina.valves.rewrite.RewriteValve
>>>> and org.apache.catalina.servlets.DefaultServlets
>>>>
>>>> If my request is forwarded by the RewriteValve and then pass into
>>>> doDirectoryRedirect in DefaultServlets to be redirected. The hidden
>>>> rewritten URI is displayed in the browser.
>>>>
>>>> To test it, try the following example (any tomcat 8, 8.5 or 9)
>>>>
>>>> add RewriteValve in conf/server.xml
>>>> <Valve className="org.apache.catalina.valves.rewrite.RewriteValve"/>
>>>>
>>>> add rewriteRule in conf/Catalina/localhost/rewrite.config
>>>> RewriteRule ^/iWantThisVisible/(.*) $/examples/$1/
>>>>
>>>> start tomcat
>>>>
>>>> go to following URLs (any internet browser) :
>>>> http://localhost:8080/iWantThisVisible/servlets
>>>> http://localhost:8080/iWantThisVisible/servlets/
>>> That behaviour is expected.
>>>
>>> If you want to stick with the RewriteValve you'll need to write a custom
>>> Valve or Filter to modify the HTTP headers on the way out.
>>>
>>> You might be better off writing a custom Servlet that does a forward.
>>>
>>> Mark
>>>
>>> ---------------------------------------------------------------------
>>> 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: Issue between RewriteValve and DefaultServlet
Posted by Mark Thomas <ma...@apache.org>.
On 26/06/17 11:22, Jérémie Barthés wrote:
> Thank for your fast answer
>
> I would like to extend DefaultServlet to override doDirectoryRedirect
> but the method is private,
> private void doDirectoryRedirect(HttpServletRequest request,
> HttpServletResponse response)
>
> May this method be protected in following versions ?
Unlikely at this point.
> i can't change a header on the way out, after server started to answer,
> can i ?
Correct. The way to handle this is to wrap the response and intercept
the call that sets the location header and modify the value before
calling the wrapped response.
Mark
>
> Regard
>
> Jeremie
>
> PS : i added a custom valve just to put non-rewritten URI in a request
> attribute, so i can use it if present when doDirectoryRedirect occurs
>
>
> Le 26/06/2017 à 12:01, Mark Thomas a écrit :
>> On 26/06/17 10:55, Jérémie Barthés wrote:
>>> Hi,
>>>
>>> I have an issue between org.apache.catalina.valves.rewrite.RewriteValve
>>> and org.apache.catalina.servlets.DefaultServlets
>>>
>>> If my request is forwarded by the RewriteValve and then pass into
>>> doDirectoryRedirect in DefaultServlets to be redirected. The hidden
>>> rewritten URI is displayed in the browser.
>>>
>>> To test it, try the following example (any tomcat 8, 8.5 or 9)
>>>
>>> add RewriteValve in conf/server.xml
>>> <Valve className="org.apache.catalina.valves.rewrite.RewriteValve"/>
>>>
>>> add rewriteRule in conf/Catalina/localhost/rewrite.config
>>> RewriteRule ^/iWantThisVisible/(.*) $/examples/$1/
>>>
>>> start tomcat
>>>
>>> go to following URLs (any internet browser) :
>>> http://localhost:8080/iWantThisVisible/servlets
>>> http://localhost:8080/iWantThisVisible/servlets/
>> That behaviour is expected.
>>
>> If you want to stick with the RewriteValve you'll need to write a custom
>> Valve or Filter to modify the HTTP headers on the way out.
>>
>> You might be better off writing a custom Servlet that does a forward.
>>
>> Mark
>>
>> ---------------------------------------------------------------------
>> 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: Issue between RewriteValve and DefaultServlet
Posted by Jérémie Barthés <j....@oodrive.fr>.
Thank for your fast answer
I would like to extend DefaultServlet to override doDirectoryRedirect
but the method is private,
private void doDirectoryRedirect(HttpServletRequest request,
HttpServletResponse response)
May this method be protected in following versions ?
i can't change a header on the way out, after server started to answer,
can i ?
Regard
Jeremie
PS : i added a custom valve just to put non-rewritten URI in a request
attribute, so i can use it if present when doDirectoryRedirect occurs
Le 26/06/2017 à 12:01, Mark Thomas a écrit :
> On 26/06/17 10:55, Jérémie Barthés wrote:
>> Hi,
>>
>> I have an issue between org.apache.catalina.valves.rewrite.RewriteValve
>> and org.apache.catalina.servlets.DefaultServlets
>>
>> If my request is forwarded by the RewriteValve and then pass into
>> doDirectoryRedirect in DefaultServlets to be redirected. The hidden
>> rewritten URI is displayed in the browser.
>>
>> To test it, try the following example (any tomcat 8, 8.5 or 9)
>>
>> add RewriteValve in conf/server.xml
>> <Valve className="org.apache.catalina.valves.rewrite.RewriteValve"/>
>>
>> add rewriteRule in conf/Catalina/localhost/rewrite.config
>> RewriteRule ^/iWantThisVisible/(.*) $/examples/$1/
>>
>> start tomcat
>>
>> go to following URLs (any internet browser) :
>> http://localhost:8080/iWantThisVisible/servlets
>> http://localhost:8080/iWantThisVisible/servlets/
> That behaviour is expected.
>
> If you want to stick with the RewriteValve you'll need to write a custom
> Valve or Filter to modify the HTTP headers on the way out.
>
> You might be better off writing a custom Servlet that does a forward.
>
> Mark
>
> ---------------------------------------------------------------------
> 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: Issue between RewriteValve and DefaultServlet
Posted by Mark Thomas <ma...@apache.org>.
On 26/06/17 10:55, Jérémie Barthés wrote:
> Hi,
>
> I have an issue between org.apache.catalina.valves.rewrite.RewriteValve
> and org.apache.catalina.servlets.DefaultServlets
>
> If my request is forwarded by the RewriteValve and then pass into
> doDirectoryRedirect in DefaultServlets to be redirected. The hidden
> rewritten URI is displayed in the browser.
>
> To test it, try the following example (any tomcat 8, 8.5 or 9)
>
> add RewriteValve in conf/server.xml
> <Valve className="org.apache.catalina.valves.rewrite.RewriteValve"/>
>
> add rewriteRule in conf/Catalina/localhost/rewrite.config
> RewriteRule ^/iWantThisVisible/(.*) $/examples/$1/
>
> start tomcat
>
> go to following URLs (any internet browser) :
> http://localhost:8080/iWantThisVisible/servlets
> http://localhost:8080/iWantThisVisible/servlets/
That behaviour is expected.
If you want to stick with the RewriteValve you'll need to write a custom
Valve or Filter to modify the HTTP headers on the way out.
You might be better off writing a custom Servlet that does a forward.
Mark
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org