Tuesday, 17 September 2013

want to write a small web server in JAVA

want to write a small web server in JAVA

I want to write a small web server that listens on for connections to
127.0.0.1 on a
TCP port provided on the command line using a sub-set of the HTTP 1.0
protocol.
This web server shall present a small page of arbitrary (possibly empty)
content in response to
an HTTP/1.0 request for /. Such a request will look like:
GET / HTTP/1.0\r\n\r\n
Where \r is carriage return (character 0x0d) and \n is line feed (character
0x0a). An appropriate response to this request might be:
HTTP/1.0 200 OK\r\nContent-length: 5\r\n\r\nHello
Requests for non-existent pages shall return HTTP response code 404,
returning something like:
HTTP/1.0 404 PAGE NOT FOUND\r\nContent-length: 14\r\n\r\nPage not
found
When presented with a request for /port/, the web server should make an
outbound
HTTP connection to the specified port number on 127.0.0.1, and request the
URL /gettoken
to obtain a token, parse the response, and use the obtained token as the
output to the HTTP
request.
For example, if an HTTP request is received for /port/12345, the web
server should make an
HTTP connection to TCP port 12345 on 127.0.0.1, and issue an HTTP request
for /gettoken,
and return the HTTP body of the response to that request as the body of
the original HTTP
request.
If the HTTP request for /gettoken fails, your web server should respond
with an appropriate
HTTP error response code (a result code in the range 500 – 599).

No comments:

Post a Comment