bowler-framework / Bowler

RESTful Web Framework based on Scala, built on top of Scalatra & Scalate
http://bowlerframework.org
BSD 3-Clause "New" or "Revised" License
118 stars 13 forks source link

Allow request forwarding #22

Open dainkaplan opened 12 years ago

dainkaplan commented 12 years ago

In Java, you can do request.getRequestDispatcher(new_url).forward(request, response) to forward requests (rather than redirect) which is very useful if you are setting values in the request rather than session. Please add this functionality to the BowlerHttpRequest class.

wfaler commented 12 years ago

After thinking about this for a while, I've figured out that there is a very simple fix for you in this case: If you do request.asInstanceOf[BowlerHttpRequest]. getHttpServletRequest you will have full access to the underlying Servlet request functionality and can do what you want to do.

If you do not have access to the request directly via your router signature, it can be accessed by RequestScope.request.

dainkaplan commented 12 years ago

@wfaler Thanks. Yeah, I realized I can get access to the http request that way, but it sort of breaks the otherwise nice encapsulation that's going on. It would be great if there were therefore a natural way to forward requests without having to do some casting and reverting back to the java versions of things. In this light, does it sound reasonable to add this feature? I did spend a minute glancing through the Bowler code, but I didn't see an apparent, easy solution. Not very familiar with Bowler internals, though.

wfaler commented 12 years ago

I think the easy way of doing it is simply to add a method to the Request trait and its implementations. Feel free to do it if you want, and I'll accept the pull request.

On 23 March 2012 14:51, Dain Kaplan < reply@reply.github.com

wrote:

@wfaler Thanks. Yeah, I realized I can get access to the http request that way, but it sort of breaks the otherwise nice encapsulation that's going on. It would be great if there were therefore a natural way to forward requests without having to do some casting and reverting back to the java versions of things. In this light, does it sound reasonable to add this feature? I did spend a minute glancing through the Bowler code, but I didn't see an apparent, easy solution. Not very familiar with Bowler internals, though.


Reply to this email directly or view it on GitHub: https://github.com/wfaler/Bowler/issues/22#issuecomment-4660411

greenrd commented 12 years ago

The comment from when this bug was closed is actually incorrect - there is no getHttpServletResponse method on the response, which you would also need to do a forward.