meerk40t / meerk40t

Hackable Laser software for K40 / GRBL / Fibre Lasers
MIT License
233 stars 62 forks source link

Fix safari data reception inside web server #2669

Closed jpirnay closed 1 week ago

jpirnay commented 1 week ago

Summary by Sourcery

Fix Safari compatibility issue in the web server's data reception method. Add a new GET interface for executing commands via URL parameters. Refactor the code to improve structure and readability, and introduce JSON response handling.

New Features:

Bug Fixes:

Enhancements:

sourcery-ai[bot] commented 1 week ago

Reviewer's Guide by Sourcery

The changes improve the web server's data handling to be compatible with Safari and add a new GET interface for command execution. The implementation has been refactored to better separate concerns, handle different response types, and properly process POST request bodies.

Sequence diagram for handling GET and POST requests

sequenceDiagram
    participant Client
    participant WebServer
    participant Context

    Client->>WebServer: Send GET/POST request
    WebServer->>WebServer: parse_received_data()
    WebServer->>WebServer: execute_data()
    alt GET request
        WebServer->>Context: Execute command from URL
    else POST request
        WebServer->>Context: Execute command from body
    end
    WebServer->>WebServer: build_response()
    WebServer->>Client: respond_with_html() or respond_with_json()

Updated class diagram for WebServer

classDiagram
    class WebServer {
        +receive(data)
        +respond_with_html(con, send_list)
        +respond_with_json(con, send_list)
        +run_server()
        -parse_received_data()
        -execute_data()
        -build_response(content)
        -build_json(content)
    }
    note for WebServer "Refactored to handle Safari compatibility and new GET interface"

File-Level Changes

Change Details Files
Refactored data reception and processing logic
  • Split receive method into smaller, focused functions
  • Added separate functions for parsing data, executing commands, and building responses
  • Improved handling of POST request bodies with proper content length processing
  • Added support for both string and bytes input data
meerk40t/network/web_server.py
Added support for GET command interface
  • Implemented command execution through URL parameters using ?cmd= syntax
  • Added URL decoding for GET command parameters
meerk40t/network/web_server.py
Improved response handling with content type support
  • Split response handling into separate HTML and JSON methods
  • Added proper content type headers for different response types
  • Implemented better error handling for connection issues
meerk40t/network/web_server.py

Tips and commands #### Interacting with Sourcery - **Trigger a new review:** Comment `@sourcery-ai review` on the pull request. - **Continue discussions:** Reply directly to Sourcery's review comments. - **Generate a GitHub issue from a review comment:** Ask Sourcery to create an issue from a review comment by replying to it. - **Generate a pull request title:** Write `@sourcery-ai` anywhere in the pull request title to generate a title at any time. - **Generate a pull request summary:** Write `@sourcery-ai summary` anywhere in the pull request body to generate a PR summary at any time. You can also use this command to specify where the summary should be inserted. #### Customizing Your Experience Access your [dashboard](https://app.sourcery.ai) to: - Enable or disable review features such as the Sourcery-generated pull request summary, the reviewer's guide, and others. - Change the review language. - Add, remove or edit custom review instructions. - Adjust other review settings. #### Getting Help - [Contact our support team](mailto:support@sourcery.ai) for questions or feedback. - Visit our [documentation](https://docs.sourcery.ai) for detailed guides and information. - Keep in touch with the Sourcery team by following us on [X/Twitter](https://x.com/SourceryAI), [LinkedIn](https://www.linkedin.com/company/sourcery-ai/) or [GitHub](https://github.com/sourcery-ai).