Skip to content

This is a basic implementation of an Hypertext Transfer Protocol (HTTP). It implements the basic functionality of HTTP/1.1, allowing for retrieval and uploading of files.

Notifications You must be signed in to change notification settings

jm4l1/jHttpServe

Repository files navigation

jHttpServe : A Basic HTTP/1.1 Server

This is a basic implementation of an Hypertext Transfer Protocol (HTTP) based on the following RFCs. It implements the basic functionality of HTTP/1.1, allowing for retrieval and uploading of files.

  • RFC 7230 - Hypertext Transfer Protocol (HTTP/1.1): Message Syntax and Routing
  • RFC 7231 - Hypertext Transfer Protocol (HTTP/1.1): Semantics and Content
  • RFC 7578 - Returning Values from Forms: multipart/form-data

Supported Operated Systems

jHttpServe currently support building on Linux and MacOs.

Dependencies for Running Locally

Basic Build Instructions

  1. Clone this repo.
  2. Init git submodules git submodule init
  3. Checkout master branch of submoduke cd lib && git checkout master
  4. Make a build directory in the top level directory: mkdir build && cd build
  5. Compile: export CXX=<path_to_g++9> && export CC=<path_to_gcc9> && cmake .. && make
  6. Run it: ./jHttpServe.

Using the application

Run application with -h flag to get help menu

$ cd build
$ ./jHttpServe -h
Usage: ./jHttpServe [-f config_file] [-h] [-p port] [-t timeout]
	-f config_file : location of configuration file in .json format
	-p port : Tcp port to accept server connections
	-t timeoutt : Time out of server to close connection
	-h : show help menu

Run application with -f specifying a JSON configuration file. The configuration file format is show below.

{
    "port" : 12345,
    "timeout" : 100,
    "server_name" :"Http Server / 1.0",
    "allowed_methods" : ["GET","OPTIONS","POST","DELETE"],
    "web_dir" : "/Users/mali/Developer/mali/cppfiles/CppND-Capstone-http-server/www"
}

A config file must be specified and exists. The file must contain the port & web_dir values or the application throws an error an exists.

$./jHttpServe -f ../server.json
config file loaded
[CreateSocket] - Starting SocketServer
[CreateSocket] - Socket Created Successfully with FD:  3
[CreateSocket] - Socket bound to port 12345
[SocketServer] - Listening on * 12345

Make request to the webserver on defined port

$curl http://localhost:12345/index.html -v
*   Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 12345 (#0)
> GET /index.html HTTP/1.1
> Host: localhost:12345
> User-Agent: curl/7.64.1
> Accept: */*
>
< HTTP/1.1 200 OK
< content-length: 108
< Connection: close
< content-type: text/html
< date: Thu, 27 Aug 2020 14:30:11 GMT
< server: Http Server / 1.0

$curl http://localhost:12345/random.html -v
* Connected to localhost (127.0.0.1) port 12345 (#0)
> GET /random.html HTTP/1.1
> Host: localhost:12345
> User-Agent: curl/7.64.1
> Accept: */*
>
< HTTP/1.1 404 Not Found
< content-length: 78
< Connection: close
< content-type: text/html
< date: Thu, 27 Aug 2020 14:30:33 GMT
< server: Http Server / 1.0

The server requests & responses are logged to the console output

Thu, 27 Aug 2020 14:29:54 GMT GET / HTTP/1.1 200 -
Thu, 27 Aug 2020 14:30:11 GMT GET /index.html HTTP/1.1 200 -
Thu, 27 Aug 2020 14:30:33 GMT GET /random.html HTTP/1.1 404 -

About

This is a basic implementation of an Hypertext Transfer Protocol (HTTP). It implements the basic functionality of HTTP/1.1, allowing for retrieval and uploading of files.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published