Skip to content

shunlir/tinyhttpd

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tinyhttpd

A simple web server for learning purpose, a revised edition of the tinyhttpd created November 1999 by J. David Blackstone.

Compile

  1. To compile, you need a Linux distribution with gcc or clang that supports C99
  2. Clone the git repository: git clone https://github.com/shunlir/tinyhttpd.git
  3. Change to the repo: cd tinyhttpd
  4. Compile: make

Play with it

  1. You need perl and its CGI module installed:
    • For Ubuntu/Debian: sudo apt-get install perl libcgi-pm-perl
    • For Fedora/RHEL/Centos: sudo yum install perl perl-CGI
  2. Start tinyhttpd: ./tinyhttpd 8088
  3. Start a web browser:
    • Enter http://localhost:8088 (client uses HTTP GET /)
    • Type a color name in the textbox, such as 'pink', click at the 'submit query' button (client uses HTTP POST /color.cgi)
    • Enter 'http://localhost:8088/color.cgi?color=pink' (client uses HTTP GET /color.cgi)

Learn the source code

  • It's quite a simple http server, only HTTP 1.0 GET and POST method
  • But it demonstrates how to serve static html files and dynmic html content generated by CGI scripts
  • Demonstrate the use of network I/O (TCP socket), file I/O, and pthread
  • Go and enjoy it! You can improve it as you like!