From 811d6b373e448b335db5de9d007944ac8e076634 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=BA=90=E6=96=87=E9=9B=A8?= <41315874+fumiama@users.noreply.github.com> Date: Thu, 10 Jun 2021 00:05:51 +0800 Subject: [PATCH] Update README.md --- README.md | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d2321a1..9f82509 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,22 @@ Created November 1999 by J. David Blackstone. Modified June 2021 by Fumiama(源文雨) +# Protocol + +A necessary subset of `HTTP 1.0` with following options of request header being supported +### From client +- Content-Length +### From server +- Content-Length +- Content-Type (only support text/plain image/x-icon text/css text/html) +- Server +### Code +- 200 OK +- 400 BAD REQUEST +- 404 NOT FOUND +- 500 Internal Server Error +- 501 Method Not Implemented + # Features 1. Serve files @@ -32,4 +48,22 @@ simple-http-server -d port chdir - **-d** - run as daemon - **port** - bind server on this port (0 for a random one) -- **chdir** - change root dir to here \ No newline at end of file +- **chdir** - change root dir to here + +# CGI usage + +When you put a executable file into the web path, the server will call `execl` to run it while passing 3 parameters as below + +```c +argv[0] = path; //Path of the executable file +argv[1] = method; //request method (GET/POST) +argv[2] = query_string; //the query string, like "a=1&b=2&c=3" +``` + +The server will read a `4 bytes` unsigned integer from pipe, indicating the `length` of the remaining content. Then it will send `length` bytes of data to the client directly with nothing being decorated, which means that you need to assemble the HTTP header by yourself. + +Here is a CGI example [CMoe-Counter](https://github.com/fumiama/CMoe-Counter) + +And its realization is here: + +