Skip to content

wa-kakalala/simple-http-server

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

50 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Shinsako

simple-http-server

A variant of Tinyhttpd.

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
  2. CGI
  3. Listen on ipv6
  4. Multi-thread

Compile

git clone https://github.com/fumiama/simple-http-server.git
cd simple-http-server
mkdir build
cd build
cmake ..
make
make install

Command line usage

simple-http-server [-d] [-p <port>] [-r <rootdir>] [-u <uid>]
  • -d: run as daemon.
  • -p: if not set, choose a random one.
  • -r: http root dir.
  • -u: run as this uid.

CGI usage

When you put an executable file into the web path, the server will call execl to run it while passing 3 parameters as below

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

And its realization is here:

About

A variant of Tinyhttpd.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C 96.9%
  • CMake 3.1%