- 
                Notifications
    You must be signed in to change notification settings 
- Fork 34
Optimize and improve request module #51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
- Cache frequently used functions for better performance - Centralize regex patterns in constants - Add better error handling and edge case protection - Improve code organization and readability - Reduce code duplication - Add more safety checks - Standardize code formatting - Optimize string operations
| Have you tested the code? I think I found some mistakes: 
 | 
This commit addresses several issues in the `wsapi.request` module, including bug fixes, performance improvements, and code quality enhancements, based on an initial code review. - **Performance**: Implemented metatable sharing for the `params` and `cookies` tables in `request.new()`. This avoids creating new metatables for each request, significantly reducing memory consumption and CPU usage under high load. - **Bug Fixes**: - Corrected a bug where `input:read(length)` was being called as a function (`input(length)`), causing errors in POST data parsing. - Fixed an issue where `post_data` was not being correctly initialized for empty POST requests with non-form-encoded content types. - Ensured that all variables are properly scoped to avoid accidental globals. - **Code Quality**: - Replaced hardcoded content type strings with constants for better readability and maintainability. - Removed unnecessary character escaping in string patterns. A new test file (`tests/test_metatable.lua`) has been added to verify the metatable sharing optimization and includes a performance benchmark.
| Hi @tomasguisasola, Thank you so much for the detailed and insightful feedback! You've pointed out some very important issues. Here’s a summary of the corrections based on your comments: 
 To validate this performance improvement, I've also added a new test file, tests/test_metatable.lua, which Thanks again for your thorough review! Let me know if you have any other questions or suggestions. | 
Removed outdated Windows Makefile and installer script.
… handles response bodies. I also expanded the tests to cover more scenarios like POST
  requests and multi-chunk responses. Additionally, I modernized the build system by improving the Makefile and configure script, making the project easier to
    build and install, and removed old installation scripts
    …or testing, installation, and uninstallation, as well as to automate the generation of rockspec files
…d user-friendly demonstration of the library's capabilitie
Performance Improvements:
Code Quality:
Maintainability: