<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, 10 Jul 2020 at 02:44, Brad Wood &lt;<a href="mailto:bdw429s@gmail.com">bdw429s@gmail.com</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">So, in my bid to put the predicate language through the paces, I&#39;ve been testing out all the rewrite rules I&#39;ve ever used with mod_rewrite or Tuckey Rewrite to see if Undertow&#39;s handlers are up to the task.  <div><br></div><div>I&#39;ve run into an issue again with probably the most common rewrite rule of any CFML app using an MVC framework, which is a rule that creates so-called &quot;SES&quot; URLs and force all requests through a front controller design pattern.  </div><div><br></div><div>Basically</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><font face="monospace"><a href="http://site.com/home/about" target="_blank">site.com/home/about</a></font></blockquote><div><br></div><div>gets rewritten to</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><font face="monospace"><a href="http://site.com/index.cfm/home/about" target="_blank">site.com/index.cfm/home/about</a></font></blockquote><div><br></div><div>Here you can see how this rule is typically accomplished in Apache httpd, Nginx, IIS, and Tuckey:</div><div><br></div><div><a href="https://coldbox.ortusbooks.com/the-basics/routing/requirements/rewrite-rules" target="_blank">https://coldbox.ortusbooks.com/the-basics/routing/requirements/rewrite-rules</a> </div><div> <br></div><div>The hang up is that<i> any incoming path that maps to an actual file</i> skips the rewrite rule.  That way<b> /images/logo.jpg</b> doesn&#39;t get rewritten. </div><div><br></div><div>So here was my first stab at it with Undertow&#39;s predicate language-- it seemed simple enough:</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><font face="monospace">not file and not directory -&gt; rewrite(&#39;/index.cfm/%{RELATIVE_PATH}&#39;)</font></blockquote><div><br></div><div>But our old friend the servlet of course is nowhere to be found since my &quot;file&quot; and &quot;directory&quot; predicates were executing in the root handler chain so there is no concept of a servlet&#39;s context root with which to resolve file system paths. </div><div><br></div><div>So basically, I understand exactly why this doesn&#39;t work, but I feel that we need to find a way to make this work.  This is a feature that pretty much every rewrite engine I&#39;ve ever used has-- the ability to test the file system to see if a file or directory exists.  Can we discuss the following options?</div><div><ul><li>Find a way for the root handler chain to access the deployment&#39;s resource manager </li></ul></div></div></blockquote><div><br></div><div>The big conceptual problem here is that there can be multiple Servlet deployments, and the rewrite could change which deployment actually gets served by the request. You could write a custom predicate to handle this, but you would need to stick the Servlet deployment in a static variable so the PredicateBuilder has access to it. We could do it with some API changes I guess, have the PredicateBuilder accept a Map&lt;String, Object&gt;, so you could pass in the ServletContext as you are building the predicates.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div><ul><li>Find a way for the rewrite handler to correctly affect not only the exchange but also (optionally) the HttpServletRequest so it&#39;s possible to rewrite the URL inside of the servlet&#39;s handler chain. I know for certain this is possible because the Tuckey Rewrite engine is implemented as a servlet filter.</li></ul></div></div></blockquote><div>This would be done using RequestDispatcher.forward(), you could write a handler that uses this, or you could write one that uses the Undertow specific io.undertow.servlet.api.Deployment#getServletDispatcher() to re-dispatch without calling forward. <br></div><div><br></div><div>Stuart<br></div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div><div><div dir="ltr"><div dir="ltr"><div><div dir="ltr"><div>I would prefer the first option since I do like having the predicates in the root handler chain so it can run as early as possible.</div><div><br></div><div>Thanks!</div><div><br></div><div>~Brad</div><div><br></div><div><b>Developer Advocate</b></div><div><i>Ortus Solutions, Corp </i></div><div><b><br></b></div><div>E-mail: <a href="mailto:brad@coldbox.org" target="_blank">brad@coldbox.org</a></div><div>ColdBox Platform: <a href="http://www.coldbox.org" target="_blank">http://www.coldbox.org</a> </div><div>Blog: <a href="http://www.codersrevolution.com" target="_blank">http://www.codersrevolution.com</a></div><div><br></div></div></div></div></div></div></div></div>
_______________________________________________<br>
undertow-dev mailing list<br>
<a href="mailto:undertow-dev@lists.jboss.org" target="_blank">undertow-dev@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/undertow-dev" rel="noreferrer" target="_blank">https://lists.jboss.org/mailman/listinfo/undertow-dev</a></blockquote></div></div>