This project is an attempt to make a command-line client (like cURL) built in C++ that allows users to perform basic HTTP requests (GET, POST, PUT, DELETE) to a specified URL. The client provides a way to specify HTTP methods, headers, and body data via command-line arguments, making it a simple yet powerful tool for interacting with web servers. The application includes components for URL parsing, request generation, and sending/receiving data over a network.
- Supports HTTP/HTTPS methods: GET, POST, PUT, DELETE.
- Allows setting custom headers and request data.
- Verbose mode to display request and response details.
- Validates URL formats and ports.
- Sends requests and handles responses using raw socket programming.
- A C++ compiler supporting C++11 or later.
- CMake (recommended for building the project).
-
Clone the repository:
git clone https://github.com/NayanPahuja/lurc.git cd lurc -
Create a build directory and compile:
mkdir build cd build cmake .. make -
Run the executable:
./lurc
To run the HTTP/HTTPS client, use the following command format:
./lurc [-v] [-X <method>] [-H <header>] [-d <data>] [-o <file_name>]<URL>-v: Verbose mode, displays detailed request and response information.-X <method>: Specifies the HTTP method to use (GET,POST,PUT,DELETE). Defaults toGET.-H <header>: Adds a header to the request in the formatKey: Value.-d <data>: Specifies the data to send in the body of the request (only applicable for methods likePOSTorPUT).<URL>: The URL to which the request is sent.
-
Basic GET request:
./lurc http://eu.httpbin.org/get
-
POST request with headers and data:
./lurc -X POST -H "Content-Type: application/json" -d '{"name": "test"}' http://eu.httpbin.org/post
-
Verbose GET request:
./lurc -v http://eu.httpbin.org/get
-
Downloading an Image:
./lurc -o test.jpg http://www.keycdn.com/img/example.jpg
- If an invalid URL or port is provided, the program will display an appropriate error message.
- Incorrect usage of options will result in detailed error messages guiding the user to correct the input format.
- main.cpp: Handles command-line parsing and controls the flow of the HTTP request process.
- url_parser.h / url_parser.cpp: Contains logic to parse URLs into components (protocol, host, port, path).
- http_client.h / http_client.cpp: Manages the creation and sending of HTTP requests and the handling of responses.
Contributions are welcome!
-
Add HEAD and PATCH method in HTTP.
-
Add handling of keep alive and using it to send multiple requests over the same TCP connection.
-
Add the ability to continue downloads by adding a flag like in curl -.
-
Add functionality depending on status codes such as Redirection etc. Use a flag
-Lto redirect location like curl. -
Add a download progress bar (optional).
-
Any vulnerabilities or improvement suggestions are always welcome!
This project is licensed under the MIT License.
- Basic socket programming concepts are adapted to provide robust error handling.
- Checkout Beej's guide to Networking for learning about networks;
- Regex is used for parsing URLs, inspired by common URL formats in web development.