Code Monkey home page Code Monkey logo

simple-http-server's Introduction

Shinsako

simple-http-server

A variant of Tinyhttpd.

Created November 1999 by J. David Blackstone.

Optimized 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
  • 403 Forbidden
  • 404 NOT FOUND
  • 500 Internal Server Error
  • 501 Method Not Implemented

Features

  1. Serve files
  2. CGI
  3. Listen on ipv6
  4. Listen on unix socket
  5. 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] [-h] [-n host.name.com:port] [-p <port|unix socket path>] [-q 16] [-r <rootdir>] [-u <uid>]
  • -d: run as daemon.
  • -h: display this help.
  • -n: check hostname and port.
  • -p: if not set, we will choose a random port.
  • -q: listen queue length (defalut is 16).
  • -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:

Appendix

4096 Threads Pressure Test Video

cmoe4096.mp4

simple-http-server's People

Contributors

fumiama avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

simple-http-server's Issues

/home/admin/Downloads/simple-http-server/server.c:172:51: error: expected ‘,’ or ‘;’ before ‘hostnameport’

/home/admin/Downloads/simple-http-server/tcpool.h:224:34: note: ‘uintptr_t’ is defined in header ‘<stdint.h>’; did you forget to ‘#include <stdint.h>’?
/home/admin/Downloads/simple-http-server/tcpool.h:224:44: error: expected ‘)’ before ‘pthread_getspecific’
224 | uint32_t index = (uint32_t)((uintptr_t)pthread_getspecific(__tcpool_pthread_key_index));
| ~ ^~~~~~~~~~~~~~~~~~~
| )
/home/admin/Downloads/simple-http-server/tcpool.h: In function ‘handle_pipe’:
/home/admin/Downloads/simple-http-server/tcpool.h:247:34: error: ‘uintptr_t’ undeclared (first use in this function)
247 | uint32_t index = (uint32_t)((uintptr_t)pthread_getspecific(__tcpool_pthread_key_index));
| ^~~~~~~~~
/home/admin/Downloads/simple-http-server/tcpool.h:247:34: note: ‘uintptr_t’ is defined in header ‘<stdint.h>’; did you forget to ‘#include <stdint.h>’?
/home/admin/Downloads/simple-http-server/tcpool.h:247:44: error: expected ‘)’ before ‘pthread_getspecific’
247 | uint32_t index = (uint32_t)((uintptr_t)pthread_getspecific(__tcpool_pthread_key_index));
| ~ ^~~~~~~~~~~~~~~~~~~
| )
/home/admin/Downloads/simple-http-server/tcpool.h: In function ‘handle_accept’:
/home/admin/Downloads/simple-http-server/tcpool.h:332:62: error: ‘uintptr_t’ undeclared (first use in this function)
332 | pthread_setspecific(__tcpool_pthread_key_index, (void*)((uintptr_t)tcpool_timer_pointer_of(p)->index+1));
| ^~~~~~~~~
/home/admin/Downloads/simple-http-server/tcpool.h:332:62: note: ‘uintptr_t’ is defined in header ‘<stdint.h>’; did you forget to ‘#include <stdint.h>’?
/home/admin/Downloads/simple-http-server/server.c: In function ‘accept_action’:
/home/admin/Downloads/simple-http-server/server.c:172:41: error: ‘uintptr_t’ undeclared (first use in this function)
172 | int host_chk_passed = !(uintptr_t)hostnameport;
| ^~~~~~~~~
/home/admin/Downloads/simple-http-server/server.c:71:1: note: ‘uintptr_t’ is defined in header ‘<stdint.h>’; did you forget to ‘#include <stdint.h>’?
70 | #include "tcpool.h"
+++ |+#include <stdint.h>
71 |
/home/admin/Downloads/simple-http-server/server.c:172:51: error: expected ‘,’ or ‘;’ before ‘hostnameport’
172 | int host_chk_passed = !(uintptr_t)hostnameport;
| ^~~~~~~~~~~~
make[2]: *** [CMakeFiles/simple-http-server.dir/build.make:76: CMakeFiles/simple-http-server.dir/server.c.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/simple-http-server.dir/all] Error 2
make: *** [Makefile:136: all] Error 2

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.