Specification for HTTP Server

Conventions:

/ -> separates components of the request

= -> separates param,value

// -> a literal / in the value (in the URL approach. No need to escape this in the query-string approach, because the delimeter is & in query strings.)

There are three ways of getting the same response.

(a) There is a global "get" url, which takes a bunch of parameters of the form param=value as in a normal query string.

(b) Same as query string above, but the global "post" url returns you the same thing.

(c) Alternatively, the param=value pairs could be separated out as components and specified in the URL itself.

A component is a part of the response. Status code, Content, headers etc are components of the response.

0. /help

Returns this spec.

1. Get a certain number of bytes

/bytes=200

OR

/get?bytes=200

(the bytes component is NOT mandatory. If bytes is not given, we return a response of 10 bytes. The bytes returned will be ALL X's. Every 10th X replaced by a \n)

2. Get a certain content-type

/bytes=200/content-type=text//html -> returns Content-type as text/html

/bytes=200/content-type=text//plain -> returns Content-type as text/plain

/get?bytes=200&content-type=text/plain

3. Get specific headers

/bytes=100/header=server: apache

4. Send a particular extension

/bytes=100/header=server: apache/any.gif

(Standard headers will be returned, unless overridden by the request. Standard headers are Connection:, Date: , Keep-Alive)

5. Not found

Anything that does not follow convention or syntax returns 404 not found.

/anythingelse.html -> returns 404

The body of the content will contain any errors that we could report, in case of syntax errors in the command. Example,

/morebytes=500

-> Returns "morebytes: not a valid component" as part of the response body in addition to the 404.

6. Get a specific status code

/status=303 -> returns 303

/status=301/header=Location: http:////10.0.0.3//new-loc -> returns a proper redirect

(Status defaults to 200 if not specified)

7. Get a specific content

/status=200/bytes=400/content-begin=123456789/content-end=987654321

Returns 400 bytes, with first 9 bytes as 123456789, last 9 bytes as 987654321 and everything else in between stuffed with X's as in the bytes spec.

/status=200/bytes=400/content=123456789/content=987654321

Contains 123456789 AND 987654321 in the content. "content" component can be repeated multiple times, but it is an error to give content-begin and content-end more than once.

8. Chunked Encoding

TBD.

9. Controlling cookies

/header=Set-Cookie: sessionid=value -> This will return a cookie

(No requirement yet for actually returning the cookie back to the server and seeing if it is valid. If we get to that requirement, we will have a special cookie component.)

10. Generate a Form

/form=GET,input.cgi/input=hidden,hidden1,initial/select=select1,4/form

This will return a form of the kind:

11. Echo parameters of POST, GET.

POST or GET /echoparams: Returns content with param=value\n.

GET /echoparams?name=vasan&number=007

-> Returns: name=vasan number=007

(as plain text)

12. Embedded URLs, links

Can achieve this using content as in 7 above. No special handling required.

13. Error handling

404s as described in (5) above.