14

When implementing a proxy server, I get an HTTP request as a string, such as this one:

GET http://localhost:54321/x HTTP/1.1

Host: localhost:54321

Cache-Control: no-cache

Is there a built-in class to parse this request?

1
  • 1
    The "built-in" classes to parse this (such as classes implementing HttpServletRequest) are part of Java Enterprise Edition and are usually integrated into a web server, which means they are not suitable for your purpose. Commented Apr 11, 2011 at 18:00

2 Answers 2

8

I don't know anything about built-in support for such parsing. If you really need such parser, you can check out this lib: http://hc.apache.org/index.html

Here's detailed example: http://www.mail-archive.com/[email protected]/msg04070.html

Sign up to request clarification or add additional context in comments.

Comments

1

if "built in" means the JDK I am pretty sure there is no class that does you bidding.

As Lukas says, HttpComponents might be of help. Even if there is no class that does exactly what you want there is code available to look at how they do it.

It is not very hard to implement this yourself though. Some string splitting will do the trick.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.