{"id":29395193,"url":"https://github.com/ydv-ankit/multi-threaded-proxy-server","last_synced_at":"2025-07-10T11:17:28.569Z","repository":{"id":301380721,"uuid":"1009046941","full_name":"ydv-ankit/multi-threaded-proxy-server","owner":"ydv-ankit","description":"A learning project for understanding socket programming in C and implementing a multi-threaded TCP proxy server.","archived":false,"fork":false,"pushed_at":"2025-06-26T15:35:09.000Z","size":2,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-06-26T15:42:00.939Z","etag":null,"topics":["c","cli-tool","gcc-complier","multithreading","proxy-server","socket-programming","web-server"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ydv-ankit.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-06-26T13:46:09.000Z","updated_at":"2025-06-26T15:35:14.000Z","dependencies_parsed_at":"2025-06-26T15:52:05.833Z","dependency_job_id":null,"html_url":"https://github.com/ydv-ankit/multi-threaded-proxy-server","commit_stats":null,"previous_names":["ydv-ankit/multi-threaded-proxy-server"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ydv-ankit/multi-threaded-proxy-server","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ydv-ankit%2Fmulti-threaded-proxy-server","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ydv-ankit%2Fmulti-threaded-proxy-server/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ydv-ankit%2Fmulti-threaded-proxy-server/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ydv-ankit%2Fmulti-threaded-proxy-server/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ydv-ankit","download_url":"https://codeload.github.com/ydv-ankit/multi-threaded-proxy-server/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ydv-ankit%2Fmulti-threaded-proxy-server/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264569733,"owners_count":23629646,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c","cli-tool","gcc-complier","multithreading","proxy-server","socket-programming","web-server"],"created_at":"2025-07-10T11:17:24.900Z","updated_at":"2025-07-10T11:17:28.561Z","avatar_url":"https://github.com/ydv-ankit.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Multi-Threaded HTTP Proxy Server\n\nA project for understanding socket programming in C and implementing a fully functional multi-threaded HTTP proxy server with request forwarding capabilities.\n\n## Overview\n\nThis project demonstrates advanced concepts of network programming in C, including multi-threaded socket handling, HTTP request parsing, proxy forwarding, and response handling. It's designed as an educational tool for learning TCP socket programming, multi-threading, HTTP protocol implementation, and proxy server architecture.\n\n## Project Structure\n\n```\nmulti-threaded-proxy-server/\n├── main.c              # Main program entry point\n├── socket/\n│   ├── socket.c        # Socket creation and multi-threading\n│   ├── socket.h        # Socket function declarations\n│   └── conn.c          # Client connection handling\n├── proxy/\n│   ├── proxy.c         # Proxy forwarding logic\n│   └── proxy.h         # Proxy function declarations\n├── utils/\n│   ├── logger.c        # Logging functionality\n│   ├── logger.h        # Logger declarations\n│   ├── parser.c        # HTTP request parser\n│   ├── parser.h        # Parser declarations\n│   ├── helper.c        # Utility functions\n│   └── helper.h        # Helper declarations\n├── Makefile            # Build configuration\n├── main                # Compiled executable\n└── README.md           # This file\n```\n\n## Currently Implemented\n\n### Core Socket Functionality\n\n- **Multi-threaded Server**: Handles multiple client connections simultaneously\n- **Socket Creation \u0026 Binding**: TCP socket creation with proper error handling\n- **Connection Acceptance**: Accepts client connections with thread creation\n\n### HTTP Request Processing\n\n- **Dynamic Buffer Management**: Handles requests larger than buffer size\n- **HTTP Request Parsing**: Manual character-by-character parsing\n- **Header Extraction**: Parses all HTTP headers into linked list structure\n- **Body Handling**: Extracts request body when present\n- **Completion Detection**: Detects complete HTTP requests with proper boundary checking\n\n### Proxy Forwarding\n\n- **URL Path Extraction**: Converts full URLs to proper HTTP request paths\n- **Request Reconstruction**: Rebuilds HTTP requests for target servers\n- **Target Server Connection**: Establishes connections to target servers\n- **Response Forwarding**: Forwards complete responses back to clients\n\n### Response Handling\n\n- **Chunked Transfer Encoding**: Properly handles chunked responses\n- **Content-Length Support**: Handles responses with Content-Length headers\n- **Complete Response Detection**: Ensures full responses are received before forwarding\n\n### Memory Management\n\n- **Dynamic Memory Allocation**: Proper buffer expansion for large requests\n- **Linked List Headers**: Efficient storage of HTTP headers\n- **Memory Cleanup**: Proper resource management\n\n## Building the Project\n\n```bash\n# Clean and build\nmake clean \u0026\u0026 make\n\n# Run the proxy server\n./main \u003cport\u003e\n```\n\n## Usage\n\n```bash\n# Start the proxy server on port 8888\n./main 8888\n\n# Test with HTTP client (Postman, curl, etc.)\n# Use localhost:8888 as the proxy server\n```\n\n## Key Functions\n\n### `initializeSocket(int port)`\n\nCreates, binds, and starts listening for connections with multi-threading support.\n\n### `handleClient(int c_fd)`\n\nHandles individual client connections with dynamic buffer management and HTTP parsing.\n\n### `parseRequest(char *buff, size_t tsize)`\n\nManually parses HTTP requests, extracting method, path, headers, and body.\n\n### `forwardRequest(struct parsed_request *req, char *req_buff, int req_buff_len, char *resp_buff, size_t *resp_len)`\n\nForwards HTTP requests to target servers and receives responses.\n\n### `receiveResponse(int tar_con_fd, char *resp_buff, size_t *resp_buff_len)`\n\nReceives complete HTTP responses from target servers, handling both chunked and Content-Length encoding.\n\n## Development Status\n\n- [x] Multi-threaded server implementation\n- [x] Dynamic buffer expansion\n- [x] HTTP request parsing (method, path, headers, body)\n- [x] Signal handling for graceful shutdown\n- [x] Memory management and cleanup\n- [x] Structured logging system\n- [x] Proxy forwarding logic\n- [x] Target server connection\n- [x] Response forwarding\n- [x] Chunked transfer encoding support\n- [x] URL path extraction and request reconstruction\n- [x] Complete response handling\n\n## Features\n\n### HTTP Protocol Support\n\n- **Methods**: GET, POST, PUT, DELETE, etc.\n- **Headers**: All standard HTTP headers\n- **Body**: Request and response body handling\n- **Encoding**: Chunked transfer encoding and Content-Length\n\n### Proxy Capabilities\n\n- **URL Parsing**: Extracts paths from full URLs\n- **Request Forwarding**: Reconstructs requests for target servers\n- **Response Handling**: Forwards complete responses to clients\n- **Multi-threading**: Handles multiple concurrent requests\n\n### Error Handling\n\n- **Connection Errors**: Proper handling of connection failures\n- **Memory Errors**: Graceful handling of allocation failures\n- **Protocol Errors**: Robust HTTP parsing with error recovery\n\n## Learning Focus\n\nThis project helps understand:\n\n### Network Programming\n\n- Socket programming fundamentals\n- Multi-threading with pthread\n- TCP connection lifecycle\n- Signal handling\n- Proxy server architecture\n\n### HTTP Protocol\n\n- HTTP request structure\n- Header parsing techniques\n- Body handling\n- Protocol completion detection\n- Chunked transfer encoding\n- URL parsing and reconstruction\n\n### Memory Management\n\n- Dynamic memory allocation\n- Buffer management\n- Linked list implementation\n- Resource cleanup\n\n### System Programming\n\n- File descriptor management\n- Thread synchronization\n- Error handling\n- Process signals\n\n## Testing\n\nThe proxy server can be tested with:\n\n- **Postman**: Send HTTP requests to any target server\n- **curl**: Command-line HTTP requests\n- **Web browsers**: Configure proxy settings\n- **Custom HTTP clients**\n\n### Example Test Scenarios\n\n```bash\n# Test with local server\ncurl -x localhost:8888 http://localhost:3000/\n\n# Test with external server\ncurl -x localhost:8888 http://httpbin.org/get\n\n# Test with Postman\n# Set proxy to localhost:8888 and send requests to any URL\n```\n\n## Enhancements can be made to the project\n\n- [ ] Request/response caching\n- [ ] Load balancing\n- [ ] Request filtering\n- [ ] Performance monitoring\n- [ ] Logging\n- [ ] Error handling\n- [ ] Memory management\n- [ ] Thread synchronization\n- [ ] File descriptor management\n- [ ] Process signals\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fydv-ankit%2Fmulti-threaded-proxy-server","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fydv-ankit%2Fmulti-threaded-proxy-server","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fydv-ankit%2Fmulti-threaded-proxy-server/lists"}