Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to parse an HTTP Request in Java?

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?

like image 397
Amir Rachum Avatar asked Apr 11 '11 17:04

Amir Rachum


2 Answers

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

like image 90
Lukasz Avatar answered Sep 18 '22 13:09

Lukasz


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.

like image 23
Mikael Vandmo Avatar answered Sep 20 '22 13:09

Mikael Vandmo