Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 

README.md

🌐 Web Proxy Server

A web proxy created using ANSI C capable of handling HTTP requests from clients to the HTTP servers. Typically the client would connect directly with the server, but useful to sometimes create/introduce an intermediate proxy. This proxy exists between the HTTP clients and HTTP servers, where the clients send HTTP requests to the proxy. Once receiving the request, the proxy forwards the request to the HTTP server. Then, the HTTP server sends a reponse back to the proxy, which in turn forwards that response to the HTTP client. This is advantageous for several reasons: performance, content filtering/transformation, and privacy.

Proxy advantages outlined: Performance: Allows caching of frequently visited pages to reduce the extra time needed for creating a new connection to the HTTP server every time. Conent Filtering and Transformation: Inspect URLs from the HTTP client to determine to block some URL connections. The other benefit is reforming webpages for clients with limited processing capabilities. In this case, an example would be something like image transcoding. Privacy: If the HTTP server tries to log information about the HTTP client, it can only get information about the proxy (not the actual client). Imagine the benefits of when there are multiple proxies involved in a route. Makes it incredibly hard to trace the orginator.

Program

Upon compiling and executing, the web proxy will listen for HTTP client requests on the designated port. The web proxy will only support HTTP GET requests, and return any errors appropriatly (Error 400, Error 500, etc.). The URL request that comes from the client is parsed into three parts:
1. Requested host and port number (default port of 80 if port is not specified) 2. Requested path, used to access resources on the HTTP server. 3. An optional message body (may not be in every HTTP request)

⚙️ SETUP

Web server testing

  • Launch the web proxy within a commonly used web browser (i.e. Chome, Firefox) and direct requests to the web proxy and port number. Example: http://localhost:3000.

📟 USE

HTTP User (client) Commands

The request consists of three parts (separated by spaces):

  1. method (GET, POST, HEAD) - Note, only GET is supported at this time
  2. URL (directory)
  3. HTTP version Example: GET http://coolestwebsiteever.com HTTP/1.1

Compiling

Note: If zipped, first unzip file before proceeding. tar -zxvf <zipfile>

  1. From root directory, run make or make webproxy from the terminal. This will generate an executable object called webproxy that is a simple we proxy to handle HTTP client requests and HTTP server responses. Follow steps in next section for execution.
  2. Make clean will remove all files generated by make.

Executing

Once web proxy object is created, run ./webproxy <PORT> in the terminal/console from the root directory of the executable file. In a separate console, run telnet localhost <PORT>, where is the port assigned in the webproxy. Once loaded, requests can be made to the proxy using the HTTP User (client) Commands format above.

Additional files:

  • blacklist.txt: list of blocked hostnames and IPs that are not allowed
  • hostname_cache.txt: list of hostnames and their IP addresses that have been resolved before
  • /pages_caches: directory to store cached webpages that have been requested

Resources

  1. Socket - accept
  2. System Calls
  3. Graceful Exits
  4. C/C++ signal handling
  5. TCP echo client and server with fork()
  6. TCP echo client and server with threads
  7. Echo server-client code with threads
  8. HTTP status codes
  9. HTTP version errors
  10. Hostname resolving
  11. Reading File Dates