A concatenated single-line string is not an HTTP header.
The correct HTTP request message should look like this (not always)
GET / HTTP/1.1 CRLF Host: localhost:9000 CRLF User-Agent: curl/7.19.7 blar blar CRLF Accept: */* CRLF Content-Length: ?? CRLF ...: ... CRLF CRLF octets
See here http://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html
If you want to implement an HTTP server without any help from Sevlets, JavaEE containers, you should use Sockets.
- Read the first line [Request-Line = Method SP Request-URI SP HTTP-Version CRLF]
- Read the request header line by line until you get an empty line
- For each header line, you can parse [fieldName: fieldValue]
- Read the body of the object.
This is NOT the only case for HTTP message contracts.
source share