A multithreaded HTTP Proxy Web Server built in C using socket programming, pthreads, DNS resolution, and an LRU (Least Recently Used) caching mechanism.
- Computer Networking
- Socket Programming
- HTTP Protocol
- Multithreading using pthread
- DNS Resolution
- Cache Management
- LRU Eviction Policy
- Linux System Programming
- Multithreaded proxy server using pthread
- HTTP request forwarding
- DNS hostname resolution
- LRU cache implementation
- Thread-safe cache handling using mutex
- Modular project architecture
- HTTP request parsing
- Client-server communication using TCP sockets
proxy_project/
β
βββ main.c
βββ server.c
βββ server.h
β
βββ thread_pool.c
βββ thread_pool.h
β
βββ proxy_handler.c
βββ proxy_handler.h
β
βββ parser.c
βββ parser.h
β
βββ dns_resolver.c
βββ dns_resolver.h
β
βββ cache.c
βββ cache.h
β
βββ lru.c
βββ lru.h
β
βββ utils.c
βββ utils.h
β
βββ Makefile
Browser
β
Proxy Server
β
Cache Lookup
β
(Cache Hit) β Return Cached Response
β
(Cache Miss)
β
DNS Resolution
β
Remote Web Server
β
Fetch Response
β
Store in LRU Cache
β
Send Response to Browser
Entry point of the proxy server.
- Initialize cache
- Initialize thread pool
- Start proxy server
Handles all server-side socket operations.
- Create socket
- Bind socket to port
- Listen for incoming clients
- Accept client connections
- Send client requests to worker threads
Implements multithreading using pthreads.
- Create worker threads
- Manage task queue
- Synchronize threads using mutex and condition variables
- Handle concurrent client requests
Core proxy logic implementation.
- Receive browser requests
- Parse HTTP requests
- Check cache
- Connect to remote servers
- Fetch responses
- Return responses to clients
Parses incoming HTTP requests.
- Extract HTTP method
- Extract host name
- Extract requested path
- Process request headers
Handles DNS resolution.
- Convert domain names into IP addresses
- Use
getaddrinfo()for hostname lookup - Resolve remote server addresses
Manages proxy cache operations.
- Store server responses
- Retrieve cached responses
- Thread-safe cache access
- Cache insertion and lookup
Implements the LRU (Least Recently Used) cache policy.
- Maintain doubly linked list
- Move recently accessed items to front
- Remove least recently used items
- Cache eviction management
Contains helper utility functions.
- Logging
- Error handling
- Common reusable helper functions
Automates project compilation.
- Compile source files
- Generate object files
- Link executable
- Clean build files
$ make
$ make cleanBrowser
β
HTTP Proxy Server
β
Thread Pool
β
Request Parser
β
LRU Cache
β
DNS Resolver
β
Remote Web Server
- C Programming
- POSIX Socket API
- pthread Library
- TCP/IP Networking
- DNS Resolution using getaddrinfo()
- Makefile
$ makeor
$ gcc *.c -o proxy -pthread$ ./proxySet browser proxy configuration:
HTTP Proxy : 127.0.0.1
Port : 8080
Then open:
http://neverssl.com
The proxy server uses an LRU (Least Recently Used) cache to improve performance by storing previously fetched responses.
-
Cache Hit
- Return cached response immediately
- Move cache node to front
-
Cache Miss
- Fetch response from remote server
- Store response in cache
- Remove least recently used entry if cache is full
The server uses a thread pool architecture:
- Main thread accepts client connections
- Worker threads process requests concurrently
- Mutex and condition variables ensure synchronization
- HTTP Proxying
- Concurrent Client Handling
- DNS Lookup
- Response Caching
- TCP Socket Communication
- HTTPS CONNECT Support
- epoll-based scalable I/O
- Dynamic memory buffering
- Full HTTP header parsing
- HashMap-based O(1) cache lookup
- Logging system
- Cache expiration mechanism
- Chunked transfer encoding support
This project helps understand:
- Low-level networking
- Concurrent programming
- Proxy server architecture
- Cache systems
- Linux networking internals
- System design fundamentals
Feel free to fork and improve this project.
This project is for learning purposes.