Repository navigation
Releases
Releases · GDB-Online-Clone/http_web_server_c
v3.0.0 Thread Pool
Release v2.0.0
Merge pull request #219 from GDB-Online-Clone/develop Develop
Release v1.0.0
Feature/http server -> develop (#141) * feat(http): implement web server execution function (#87) - Implemented run_web_server function for handling core server operations - Added basic server functionality including HTTP request processing and routing - Established socket communication for receiving client requests and sending responses - Implemented resource cleanup logic to prevent memory leaks Key features: - Server socket initialization and configuration - Client connection acceptance and request handling - HTTP request parsing and routing - Dynamic memory management * feat(http): add web server structure and function declarations (#82) - Added web_server structure declaration for managing server state and configuration - Defined run_web_server function interface for server execution - These declarations in http.h provide the foundation for future web server implementation - Includes essential components like routing table, status code, and response body management * refactor(server): improve web server code structure and stability (#104) - Modularized server code by separating core functionalities into independent functions - Enhanced error handling and resource cleanup mechanisms - Added comprehensive documentation for each function using Doxygen style - Improved code readability through better organization and smaller function sizes - Strengthened memory management with dedicated cleanup routines * test(server): implement concurrent client connection test cases (#104) - Implemented test cases to verify server's concurrent connection handling - Added verification for multiple simultaneous client connections - Included test cases for invalid request handling - Enhanced server reliability and stability assurance through comprehensive testing * feat: Add Structures and Functions for Route Handling (#106) * feat(router): add routes struct for managing server routes (#89) - Added the `routes` struct to efficiently manage routes on the server. - This struct allows for more systematic registration and management of routes. * feat(router): add init_routes function for initializing routes struct (#102) - Added the `init_routes` function to initialize the `routes` struct. - This function sets up the initial state of `routes`, including memory allocation and initialization logic. - It simplifies the process of creating and initializing the `routes` struct simultaneously. * test(router): add unit test for init_routes function (#102) - Added a unit test to verify the functionality of the `init_routes` function. - The test ensures that the `routes` struct is initialized correctly. - This test checks the value of `size`, `capacity` and that `items` has been allocated successfully * feat(utils): add utility function for comparing two URL paths (#105) - Added the `url_path_cmp()` function to compare if two URL paths are identical. - The function ignores trailing slashes, ensuring paths with or without '/' at the end are considered equal. * test(utils): add test cases for `url_path_cmp()` function (#105) - Added test cases for inputting two exactly identical URL paths. - Added cases to test URL paths that only differ by the presence of trailing '/'. - Included test cases for completely different URL paths. * feat(router): add `find_route()` function for searching a route (#84) - Added the `find_route()` function to search for a route based on given input. - This function locates an appropriate route from the routing table and returns related information. - Each route is distinct, with the path and method as keys * test(router): add test cases for `find_route()` function (#84) - Included tests for paths that match directly. - Wrote test cases for when the route does not exist in the routing table. * feat(router): add `insert_route` function for registering new route in `struct routes` (#83) - Added the `insert_route` function to register new routes in the `routes` struct. - This function is designed to allow registration of routing information for specific paths and http methods. - Function can return NULL when the same route already exists in given route table. * test(router): write test cases for `insert_route()` function (#83) - Added test case to verify insert failure when the same route already exists. - Wrote test case to ensure a new route is added to the given routing table. - Included a bulk test case adding 100 routes sequentially. * feat(http_header) add `find_header` Function (#9) - Search a header with `key` from given struct http_headers - Return a header matched by `key` * test(http_header): write test cases for `find_header()` function (#9) - Added test cases for when a given key exists in the headers. - Wrote test cases for when a given key does not exist in the headers. - Included verification with the found header's value in cases where the key exists. --------- Co-authored-by: JEON, JONGYOUNG <74577670+jongyoung3@users.noreply.github.com> * refactor(server): convert web server implementation to synchronous mode (#104) - Changed the server implementation to handle requests synchronously - Modified request handling to process client requests sequentially in a single thread - Added explicit resource cleanup after HTTP request processing to prevent memory leaks - Implemented proper handling for client disconnection scenarios * chore(test): remove test code for synchronous web server (#104) - Removed test code that was designed for the previous concurrent implementation - Removed test_run_web_server_multiple_clients test function - Removed test_run_web_server_invalid_request test function - Removed client_thread helper function for concurrent testingchore(test): remove test code for synchronous web server - Removed test code that was designed for the previous concurrent implementation - Removed test_run_web_server_multiple_clients test function - Removed test_run_web_server_invalid_request test function - Removed client_thread helper function for concurrent testing * test(server): implement web server initialization and routing tests (#111) Added unit tests to verify core functionalities of the web server. The tests cover server initialization, route handling, and HTTP response generation. Cleanup code for memory leak prevention has been implemented as well. Key implementations: - Server initialization and basic configuration validation - Route registration and lookup functionality verification - HTTP response generation and string conversion testing * refactor(server): improve resource management and error handling in web server (#104) Enhanced server stability and resource management. Added appropriate close calls at all error conditions and connection terminations to prevent socket and file descriptor leaks. Changes made: - Implemented thorough resource management logic for both server (server_fd) and client sockets (new_socket) - Ensures safe cleanup in error conditions - Added systematic socket closure at all termination points * feat(http-response): Enhance HTTP response handling (#112) * feat(http): add function to convert HTTP version to string (#81) - Added the `http_version_stringify` function to convert HTTP version enums to strings. - This function provides user-friendly string representations of HTTP versions, returning "Unknown" for unsupported versions. * feat(http): add extended HTTP status codes (#107) - Added new 2xx, 3xx, and 4xx status codes to `http_status_code`. - Includes HTTP_CREATED(201), HTTP_MOVED_PERMANENTLY(301), HTTP_BAD_REQUEST(400), and more for better HTTP response handling. * feat(http): add function to stringify HTTP status codes (#93) - Implemented `http_status_code_stringify` to convert HTTP status codes to their reason phrases. - Handles 2xx, 3xx, 4xx, and 5xx categories, returning appropriate phrases. - Returns "Unknown" for unsupported status codes. * feat(http): add HTTP_PUT and HTTP_DELETE methods to `http_method` enum (#108) - Added `HTTP_PUT` and `HTTP_DELETE` to the `http_method` enum for expanded HTTP method support. - This change ensures that the system can handle PUT and DELETE requests effectively alongside existing GET, POST, and other methods * feat(http): add stringify function for `http_method` enum (#94) - Added `http_method_stringify` function to convert `http_method` enum values to their string representation. - Supported methods include GET, POST, PUT, DELETE, and UNKNOWN. - This function enhances readability and debugging by providing a clear textual representation of HTTP methods. * feat(http): add `init_http_response` function (#6) - Added the `init_http_response` function to initialize HTTP response objects. - This function initializes an `http_response` struct with specified status code, headers, version, and body. - Included clear documentation in the code to ensure ease of understanding and proper usage. * feat(http): add function to stringify HTTP headers (#109) - Added `http_headers_stringify` function to convert an HTTP headers struct into a string. - The function formats header keys and values, allocates memory, and returns the formatted string. Returns `NULL` for empty headers or memory allocation failure. * feat(http): implement HTTP response stringify function (#7) - Added `http_response_stringify` function to convert HTTP response objects into strings. - Combines HTTP headers, status code, version, and body to generate a single HTTP response string. * fix(http): fix typo in function name (#110) - Renamed `http_status_code_stringfy` to `http_status_code_stringify`. * [Redo] feat: Add Structures and Functions for Route Handling (#113) * feat(router): add routes struct for managing server routes (#89) - Added the `routes` struct to efficiently manage routes on the server. - This struct allows for more systematic registration and management of routes. * feat(router): add init_routes function for initializing routes struct (#102) - Added the `init_routes` function to initialize the `routes` struct. - This function sets up the initial state of `routes`, including memory allocation and initialization logic. - It simplifies the process of creating and initializing the `routes` struct simultaneously. * test(router): add unit test for init_routes function (#102) - Added a unit test to verify the functionality of the `init_routes` function. - The test ensures that the `routes` struct is initialized correctly. - This test checks the value of `size`, `capacity` and that `items` has been allocated successfully * feat(utils): add utility function for comparing two URL paths (#105) - Added the `url_path_cmp()` function to compare if two URL paths are identical. - The function ignores trailing slashes, ensuring paths with or without '/' at the end are considered equal. * test(utils): add test cases for `url_path_cmp()` function (#105) - Added test cases for inputting two exactly identical URL paths. - Added cases to test URL paths that only differ by the presence of trailing '/'. - Included test cases for completely different URL paths. * feat(router): add `find_route()` function for searching a route (#84) - Added the `find_route()` function to search for a route based on given input. - This function locates an appropriate route from the routing table and returns related information. - Each route is distinct, with the path and method as keys * test(router): add test cases for `find_route()` function (#84) - Included tests for paths that match directly. - Wrote test cases for when the route does not exist in the routing table. * feat(router): add `insert_route` function for registering new route in `struct routes` (#83) - Added the `insert_route` function to register new routes in the `routes` struct. - This function is designed to allow registration of routing information for specific paths and http methods. - Function can return NULL when the same route already exists in given route table. * test(router): write test cases for `insert_route()` function (#83) - Added test case to verify insert failure when the same route already exists. - Wrote test case to ensure a new route is added to the given routing table. - Included a bulk test case adding 100 routes sequentially. * feat(http_header) add `find_header` Function (#9) - Search a header with `key` from given struct http_headers - Return a header matched by `key` * test(http_header): write test cases for `find_header()` function (#9) - Added test cases for when a given key exists in the headers. - Wrote test cases for when a given key does not exist in the headers. - Included verification with the found header's value in cases where the key exists. --------- Co-authored-by: JEON, JONGYOUNG <74577670+jongyoung3@users.noreply.github.com> * feature(webserver): add test_webserver.sh script (#114) - Added a new `test_webserver.sh` script to validate the proper functioning of the web server. - This script checks key functionalities, ensuring the server operates as expected in various scenarios. - Aimed at simplifying debugging and verifying setup consistency. Co-Authored-By: Gurum <129149352+sony-string@users.noreply.github.com> Co-Authored-By: JEON, JONGYOUNG <74577670+jongyoung3@users.noreply.github.com> * refactor(server): improve web server struct definition and documentation (#116) - Improved web server struct definition and reorganized documentation - Moved global function declarations to the top for better code structure - Modified struct member documentation style for consistency Key changes: - Relocated run_web_server function declaration to the top - Removed unnecessary members from web_server struct (status_code, body) - Switched to inline documentation style for struct members - Enhanced server configuration flexibility with backlog setting * fix(http): resolve error caused by uninitialized `header_string` variable (#119) - Fixed an issue where the `header_string` variable was not initialized, causing errors in the `http_response_stringify` function. - Updated the logic to ensure `header_string` is assigned an empty string (`""`) when it is `NULL`. - This resolves potential null pointer dereferences and improves the stability of the HTTP response stringification process. Co-Authored-By: Gurum <129149352+sony-string@users.noreply.github.com> Co-Authored-By: JEON, JONGYOUNG <74577670+jongyoung3@users.noreply.github.com> * refactor(test): comprehensive cleanup of web server test code (#125) - Removed all unit tests for routing system functionality - Removed web server initialization tests - These tests will be replaced with actual server operation tests Removed tests: - Server initialization tests: - test_web_server_init - test_web_server_invalid_port - test_web_server_empty_routes - Routing system tests: - test_url_path_cmp - test_insert_route - test_find_route - test_init_routes_1 Co-Authored-By: Gurum <129149352+sony-string@users.noreply.github.com> Co-Authored-By: 박수현 <54769955+xharpenParksuhyeon@users.noreply.github.com> * refactor(webserver): rename `new_socket` to `client_socket` in `run_web_server()` (#127) - enhance readibility Co-authored-by: JEON, JONGYOUNG <74577670+jongyoung3@users.noreply.github.com> Co-authored-by: 박수현 <54769955+xharpenParksuhyeon@users.noreply.github.com> * fix(http.c): use `find_route` function for route searching in `run_web_server` (#126) - Fixed the issue where route searching was implemented directly, which violated the SPOT principle, and changed it to use the existing `find_route` function. - This change improves code consistency and maintainability. Co-authored-by: JEON, JONGYOUNG <74577670+jongyoung3@users.noreply.github.com> Co-authored-by: 박수현 <54769955+xharpenParksuhyeon@users.noreply.github.com> * fix(http.c): add buffer initialization to prevent contamination during `read` (#123) - Addressed the issue of HTTP request contamination by previous buffer contents by adding `memset` for buffer initialization. - Ensures the accuracy of request data through buffer initialization. Co-authored-by: JEON, JONGYOUNG <74577670+jongyoung3@users.noreply.github.com> Co-authored-by: 박수현 <54769955+xharpenParksuhyeon@users.noreply.github.com> * refactor(http.c): replace log outputs with `DLOGV` in `run_web_server` (#121) - Replaced `printf` log outputs with `DLOGV` function to enhance debugging convenience. - Using `DLOGV` allows easier filtering and management of logs when needed. Co-authored-by: JEON, JONGYOUNG <74577670+jongyoung3@users.noreply.github.com> Co-authored-by: 박수현 <54769955+xharpenParksuhyeon@users.noreply.github.com> * refactor(http.c): improve error return in `run_web_server` for better debugging (#120) - Modified the `run_web_server` function to return `errno` instead of -1 when `socket`, `bind`, or `listen` functions fail before entering `while(1)`. - This change allows for more accurate error analysis when failures occur. Co-authored-by: JEON, JONGYOUNG <74577670+jongyoung3@users.noreply.github.com> Co-authored-by: 박수현 <54769955+xharpenParksuhyeon@users.noreply.github.com> * style(http.c): improve formatting of local variable declarations in `run_web_server` (#117) - Enhanced the formatting of local variable declarations in the `run_web_server` function for consistency and readability. - Adjusted spacing and alignment of variable declarations to improve code clarity. Co-authored-by: JEON, JONGYOUNG <74577670+jongyoung3@users.noreply.github.com> Co-authored-by: 박수현 <54769955+xharpenParksuhyeon@users.noreply.github.com> * refactor(http.c): change buffer to fixed size for `read()` (#128) - Modified the buffer setting in the `read()` function to use a fixed-size buffer instead of a dynamic-sized buffer. - This change simplifies memory management and enhances performance stability. * feat(server): implement web server test endpoints (#118) - Implemented test endpoints to verify basic web server functionality - Added endpoints for hello-world, string pattern search, and request body mirroring - Set up main function for server testing Key changes: - Implemented /hello-world GET endpoint - Added string pattern search functionality (aaba pattern) - Added request body mirroring functionality - Configured main function for testing - Commented out debug log code Co-Authored-By: Gurum <129149352+sony-string@users.noreply.github.com> Co-Authored-By: 박수현 <54769955+xharpenParksuhyeon@users.noreply.github.com> * chore(main): ignore or resolve some warnings in main.c (#129) - ignore "-Wunused-function" warnings in main.c - ignore "-Wunused-variable" warnings in main.c - resolve "-Wparentheses" warning at **[src/main.c:27]** * style(webserver): fix some missing indent (#130) - there was some lines with no indent while there need indents. * style(http.c): Fix some missing indent (#130) * feat(http): implement query parameter lookup functionality (#12) - Added find_query_parameter function to search for query parameters by key - Implemented NULL pointer validation for both query parameters and key inputs - Ensured safe string comparison using strcmp for key matching - Added proper error handling by returning NULL for non-existent parameters This implementation provides a safe and consistent way to handle HTTP query parameters. * docs(todo): add todo * refactor(route): change return type of `callback` and update related functions (#134) - Changed the return type of the `route::callback` member from `struct response` to `struct response *`. - Updated the data type of `callback` parameter in `insert_route` to a function pointer returning `struct response *`. - The `callback` must now return memory allocated by malloc, or similar. - Modified `run_web_server()` to change the local `response` variable to a pointer, in line with the new `callback` return spec. - Added logic to `run_web_server()` to free the memory of `response`. - Updated `run_web_server()` to return an HTTP status code 500 when the `callback` return value is NULL. - Revised the test router's callback function in `main.c` to align with the new `route::callback` spec. - Revised the test router's callback function in `test/unittest.c` to align with the new `route::callback` spec. * refactor(http): change return type of `parse_http_request` to pointer (#136) - Changed the return type of `parse_http_request` from `struct http_request` to `struct http_request*`. - Updated `run_web_server()` to modify the local `request` variable to a pointer following the change in `parse_http_request` return specs. - Added logic to `run_web_server()` to free the memory of `request`. - Updated test code in `test/unittest.c` to align with the return type change of `parse_http_request`. * feat(http): add `destruct_http_request` function for deallocating `struct http_request` members (#135) - Added `destruct_http_request` function to safely deallocate member variables in `struct http_request`. - This helps prevent memory leaks and ensures proper memory management after the struct usage. * feat(webserver): add error handling logic during server run (#137) - Added logic to return HTTP status code 500 on `read` failure. - Added logic to return HTTP status code 404 on `find_route` failure. - Initialized `response` as a local variable for 404 and 500 responses. - Modified to ensure `free(response)` is not called on 404/500 errors. * test(http): fix omission of `parse_http_request()` unit test registration (#138) - Fixed the omission of registering the unit test for `parse_http_request()`. - All relevant test cases are now included in the build and execution process. * bug(http_request): `parse_http_request()` need to have error handling logic for invalid input (#131) - now able to handle request with no headers. (Return **NULL**) - now able to handle completely malformed HTTP requests. - add test case for `parse_http_request()` with above cases. * fix(main.c): update test callback function (#134) - Modified the test route callback function to provide the body using dynamically allocated memory instead of string literals. --------- Co-authored-by: JEON, JONGYOUNG <74577670+jongyoung3@users.noreply.github.com> Co-authored-by: 박수현 <54769955+xharpenParksuhyeon@users.noreply.github.com> Co-authored-by: jongyoung3 <jongyong5645@gmail.com>