Code Monkey home page Code Monkey logo

jhttpserve's Introduction

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 -

jhttpserve's People

Contributors

jm4l1 avatar

Watchers

James Cloos avatar  avatar

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.