This is a simple and functional C web server designed specifically for Windows systems. It serves static HTML files to clients over HTTP and utilizes Windows-specific APIs.
Before you begin, ensure you have met the following requirements:
- You have a basic understanding of the C programming language.
- You have
gcc
installed on your Windows system. - You are running this on a Windows system.
To install and run the server, follow these steps:
-
Clone the repository:
git clone https://github.com/AdaiasMagdiel/windows-c-http-server.git
-
Navigate to the project directory:
cd windows-c-http-server
-
Build the project using
Makefile
:make
-
Run the server:
./main.exe
Once the server is running, it will listen for incoming connections on http://0.0.0.0:3000/
. You can access the server using a web browser or tools like curl
.
The project consists of the following files:
main.c
: Contains the main function where the server is initialized and client connections are handled.src/server.c
: Implements functions for initializing the server socket, accepting connections, and sending data.src/server.h
: Header file for server-related functions.src/content.c
: Implements functions for reading HTML files and generating appropriate HTTP responses.src/content.h
: Header file for content-related functions.src/request.c
: Implements functions for parsing HTTP requests.src/request.h
: Header file for request-related functions.Makefile
: Defines rules for building the project.
The web server supports the following functionalities:
-
Serve Static HTML Files:
- Serves files from the
./public
directory by default. - Supports serving
index.html
for root requests.
- Serves files from the
-
HTTP Request Handling:
- Parses HTTP requests to extract the method and path.
-
Dynamic Content Type Handling:
- Determines the content type of requested files based on their extensions (e.g.,
.html
,.css
,.js
). - Defaults to
text/plain
for unknown file types. - This approach is not the most efficient/optimal/recommended for this project, but it serves its purpose for now.
- Determines the content type of requested files based on their extensions (e.g.,
-
HTTP Response Generation:
- Generates appropriate HTTP headers.
- Handles 404 Not Found responses for non-existent files.
This project is specifically designed for Windows systems and utilizes Windows-specific APIs. To run it on Linux, you may need to make adjustments to the code to replace Windows APIs with their Linux equivalents.
Contributions are welcome! Feel free to open an issue or submit a pull request.
This project is licensed under the MIT License - see the LICENSE
file for details.