Giter Site home page Giter Site logo

http-server's Introduction

HTTP-Server

Partial implementation of HTTP utilizing OOP Principles.

  • Threaded (multiple clients)
  • GET only.
  • Handling Request status.
  • Error handling:
    • Redirection
    • Page Not Found
    • Bad Request
    • Internal Server Error


Starting the Server

  • Accept multiple clients by starting a thread for each accepted connection.
  • Keep on accepting requests from the remote client until the client closes the socket (sends a zero length message).
  • For each received request, the server must reply with a response.

Receiving Request

The received request must be a valid HTTP request, else return 400 Bad Request.

What is valid HTTP request?

  • Check single space separating the request line parameters.
    • Method URI HTTP-Version
  • Check blank line separating the header lines and the content, even if the content is empty.
  • Check valid URI
  • Check at least request line and host header and blank lines exist.

Response Headers

The response includes the following headers:

  • Content-Type: We used only text/html
  • Content-Length: The length of the content sent in the response.
    • This can be useful for the client to know how much data to expect and for the server to know how much data to send.
      Example: When downloading a file from internet, the broweser looks at this header to determine how big the file is.
  • Date: Current DateTime of the server.
  • Location: Only if there is redirection.

Handling Request

Using Configuration.RootPath, map the URI to the physical path.

Example:
configuration.RootPath= “c:\intepub\wwwroot\fcis1” and URI = “/aboutus.html”
then physical path= “c:\intepub\wwwroot\fcis1\aboutus.html”


Error handling

Redirection
If the URI exists in the configuration.RedirectionRules,
then return 301 Redirection Error and add location header with the new redirected URI.
The content should be the content of the static page “redirect.html”
Not Found
If the physical file is not found,
return 404 Not Found error.
The content should be the content of the static page “Notfound.html”
Bad Request
If there is any parsing error in the request,
return 400 Bad Request Error.
The content should be loaded with the content of the static page “BadRequest.html”
Internal Server Error
If there is any unknown exception,
return 500 Internal Server Error.
The content should be the content of the static page “InternalError.html”

Run the server

Try the following URIs in the web browser:

http://localhost:1000/aboutus2.html
should display aboutus2.html page.

http://localhost:1000/aboutus.html
should display aboutus2.html (Redirection).

http://localhost:1000/main.html
should display main page.

http://localhost:1000/blabla.html
should display 404 page.


http-server's People

Contributors

basmallahhisham avatar

Watchers

 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.