jakartaee / servlet

Jakarta Servlet
https://eclipse.org/ee4j/servlet
Other
262 stars 83 forks source link

Proposal: add getCompleteRequestURI() and getCompleteRequestURL() #462

Open devxzero opened 2 years ago

devxzero commented 2 years ago

Information that is commonly needed from HttpServletRequest is the URL or URI in its complete form. But currently, there is no such feature in Servlet, which raises a lot of questions for new developers, as is demonstrated in this highly voted Stackoverflow question.

The request-target in the HTTP RFC is the complete URI. URIs are specified in the origin-form. The problem with Servlet is that the Servlet API doesn't provide this vital part of the HTTP request, but strips it down, and then provides parts of it separately. So users have to find methods to reconstruct it again back to it's original form, which can introduce bugs. Users expect that the existing methods [getRequestURI()](https://docs.oracle.com/javaee/6/api/javax/servlet/http/HttpServletRequest.html#getRequestURI()) and [getRequestURL()](https://docs.oracle.com/javaee/6/api/javax/servlet/http/HttpServletRequest.html#getRequestURL()) provide what they are looking for, but then find that their application isn't behaving as expected, and have to resort to the JavaDocs to find out that these methods aren't providing complete information.

These problems would be solved if new methods with names like getCompleteRequestURI() or getFullRequestURI(), and getCompleteRequestURL() or getFullRequestURL(), would be added to HttpServletRequest.