Problem: Use of a urlrewrite rule that has a condition that consumes request
input stream makes it impossible for any other downstream filter/servlet to
consume it as a stream.
For instance when jruby/rack servlet passes the request on to rails, and rails
doesn't understand java HttpServletRequest and doesn't read parameters
directly. In such cases the framework(in this case rails) tries to read the
request input stream and parse out the payload from it, but this fails because
urlrewrite condition consumes the stream while reading parameters. There
appears to be no way to avoid this stream dereferencing either, because 'and'
is not short-circuited.
What steps will reproduce the problem?
Add following url rewrite rules
<rule>
<name>Initialize _method translation</name>
<from>.*</from>
<set name="do_not_set_method">false</set>
</rule>
<rule>
<name>Special request that does not require method setting</name>
<from>^/((foo)|(bar))$</from>
<to last="true">/special_req/$1</to>
<set name="do_not_set_method">true</set>
</rule>
<rule>
<name>Reset _method attribute if _method parameter is passed in</name>
<condition type="attribute" name="do_not_set_method">false</condition>
<condition type="parameter" name="_method">.+</condition>
<from>.+</from>
<set name="_method">%{parameter:_method}</set>
</rule>
What is the expected output? What do you see instead?
When its a 'special request'(matched by second rule), condition evaluation for
'reset _method' should not dereference stream contents in an attempt to read
parameters, as the first condition for 'reset _method' is not met. But since
'and' doesn't short-circuit, it dereferences it anyway, which means
dereferencing of input stream can not be avoided.
What version of the product are you using? On what operating system?
3.2.0/Gentoo
Please provide any additional information below.
This patch short-circuits AND conditions, which means in the example above, the
first condition failing will prevent the evaluation of second condition, hence
making it possible to avoid dereferencing of input stream.
NOTE: this is a 'git format-patch' generated patch. Please use 'patch -p1 -i
0001-AND-conditions-now-shortcircuit.patch'
This cleanly applies on 3.2.0 branch as well.
Original issue reported on code.google.com by singh.janmejay on 10 Aug 2010 at 11:09
Original issue reported on code.google.com by
singh.janmejay
on 10 Aug 2010 at 11:09Attachments: