back to scratko.xyz
aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorscratko <m@scratko.xyz>2025-07-26 04:12:32 +0300
committerscratko <m@scratko.xyz>2025-07-26 14:49:25 +0300
commita25d6ead498166e3fd6b0e3d95c009ae1aa55172 (patch)
tree07147647d374a19b99acc57d6be3b19fa78dab86
parent9d5e8d5b2ab5ff406da3f956db1a8c1716af4cbd (diff)
downloadhttp-server-master.tar.gz
http-server-master.tar.bz2
http-server-master.zip
Added READMEHEADmaster
-rw-r--r--README.md86
-rw-r--r--http_server.pngbin0 -> 23866 bytes
2 files changed, 86 insertions, 0 deletions
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..10c768d
--- /dev/null
+++ b/README.md
@@ -0,0 +1,86 @@
+# Simple HTTP/1.1 Web Server
+
+<img src="http_server.png" />
+
+## Description
+
+This project is a lightweight web server implemented in C, using raw TCP sockets
+and the POSIX API. It serves static files from a specified resource directory
+and handles multiple clients concurrently in a non-blocking fashion.
+
+### Features
+
+* Implements the HTTP/1.1 protocol (basic subset).
+* Handles GET requests for static files.
+* Uses non-blocking I/O with select.
+* Manages multiple client sessions via a custom session array.
+* Basic request parsing with a finite state machine (FSM).
+* Logs events using syslog.
+* Sends appropriate HTTP responses, including 400 Bad Request and 404 Not Found.
+
+## Technologies Used
+
+* C (ISO C90/C99)
+* POSIX sockets API (socket, bind, accept, etc.)
+* Non-blocking I/O with select
+* TCP/IP Networking
+* Syslog logging
+
+## Structure
+
+`struct server`: represents the server and holds the listening socket and
+session array. `struct session`: represents a connected client and holds state
+and buffers. Custom FSM (`enum fsm_states`) for request parsing and response
+generation. Defines for buffer sizes and constants allow easy tuning.
+
+## Usage
+
+Compile with:
+
+```
+git clone https://git.scratko.xyz/http-server
+cd http-server
+gcc -Wall -O2 http_server.c -o http_server
+```
+
+Run:
+```
+./http_server [port] [host] [resource_directory]
+```
+
+Example:
+```
+./http_server 8082 test.scratko.xyz:8082 /var/www/test
+```
+
+## Notes
+
+Only basic HTTP/1.1 functionality is supported (no keep-alive, POST, etc.).
+Designed for educational and experimental purposes.
+Ensure the resource directory and files have proper read permissions.
+
+The http-server directory contains a ``test_files`` subdirectory with the files:
+`400.html`, `404.html`, and `index.html`. These are placeholder pages that can
+be placed in the resource directory specified when launching the server
+(`[resource_directory]`). If the server starts correctly, you should see
+`index.html` in your browser (as shown in the screenshot).
+
+If the browser sends an incorrect GET request, or if you specify an incorrect
+host when launching the server — for example:
+
+```
+server 8082 test.scrato.xyz:8082 /var/www/test
+```
+
+Note the intentional typo in the hostname (scrato instead of scratko). Then,
+when the browser accesses test.scratko.xyz:8082, it will receive the `400.html`
+page (Bad Request).
+
+Another case: if you try to access a nonexistent section or file of the site,
+for example:
+
+```
+test.scratko.xyz:8082/test
+```
+
+you will receive the `404.html` page (Page Not Found).
diff --git a/http_server.png b/http_server.png
new file mode 100644
index 0000000..a4c7092
--- /dev/null
+++ b/http_server.png
Binary files differ