javahttprequest

Parsing HTTP requests


When dealing with the requests of type

GET /someFile.txt HTTP/1.1

Is there a library that will help you find /someFile.txt with ease, or is it common to manually split and parse things? No big deal, just wondering.

message.split("\\s+")[1] // works but just looks silly

Solution

  • If you're on the server (servlet container) side, HttpServletRequest.getPathInfo should do the job.

    http://tomcat.apache.org/tomcat-5.5-doc/servletapi/javax/servlet/http/HttpServletRequest.html#getPathInfo()