Skip to content

New version of the Relic webserver - adopted from Shelf - #2744

Closed
klkucaj wants to merge 158 commits into
serverpod:mainfrom
klkucaj:improvement/rfc
Closed

klkucaj wants to merge 158 commits into
serverpod:mainfrom
klkucaj:improvement/rfc

Conversation

@klkucaj

@klkucaj klkucaj commented Sep 12, 2024 •

Copy link
Copy Markdown
Contributor

This PR introduces Relic, a lightweight and strictly typed HTTP server designed to work seamlessly with [Serverpod](https://serverpod.dev). Inspired by Shelf, Relic focuses on type safety, performance, and modularity while maintaining extensibility.

Key Features

Core Library (lib/)

  • relic.dart:

    • The primary entry point of the library, exposing the core server functionalities.
  • lib/src/:
    This directory organizes the core logic into specialized modules to ensure clarity, scalability, and maintainability.

    • Core Server Files:

      • relic_server.dart: Implements the primary server functionality backed by Dart's HttpServer, handling connections, routing, and core features.
      • relic_server_serve.dart: Provides functionality for serving HTTP requests, with support for advanced features like request hijacking.
    • Modules:

      • handler/: Implements mechanisms for flexible request routing, delegation, and pipelines for chaining handlers.
      • middleware/: Contains utilities to integrate middleware, including extensions and logging functionality for monitoring requests and responses.
      • logger/: Provides structured logging for better observability and debugging.
      • util/: Shared utility functions for common operations within the library.
      • body/: Handles parsing, validation, and type-checking of request/response bodies.
      • message/: Manages HTTP message formatting, including request.dart and response.dart for processing requests and responses.
      • headers/:
        The headers module is a central component of the Relic library, offering robust functionality for handling HTTP headers:
        • Core Functionality:
          • headers.dart: Provides the main abstraction for managing HTTP headers, integrating with various submodules.
          • extension/: Adds utility methods for working with headers represented as strings, enabling ease of use and flexibility.
        • Parsing:
          • parser/: Includes headers_parser.dart and common_types_parser.dart to convert raw headers into structured, validated formats.
        • Type-Safe Headers:
          • typed/: Offers predefined and user-defined typed headers, improving reliability and ensuring correctness.
        • Custom Headers:
          • custom/: Allows for the definition and management of application-specific headers.
        • Error Handling:
          • exception/: Defines error types for invalid or improperly formatted headers, ensuring reliability.
      • static/: Implements the logic for serving static files, including custom directory listings and optimizations for asset handling.
      • hijack/: Provides request hijacking for advanced use cases requiring low-level control.
      • method/: Manages and validates HTTP methods, ensuring adherence to standard protocols.

Test Suite (test/)

The test/ directory includes a comprehensive set of unit and integration tests that validate Relic's features and reliability.

  • Core Test Files:

    • relic_server_test.dart: Tests the primary server's functionality, including routing and connection handling.
    • relic_server_serve_test.dart: Focuses on validating the server's serve logic and advanced features like request hijacking.
  • Subdirectories:

    • handler/: Verifies the routing, delegation, and pipeline mechanisms.
    • middleware/: Tests middleware integration, extensions, and logging functionality.
    • util/: Tests utility functions for correctness and performance.
    • message/: Focuses on request and response message formatting and parsing.
    • headers/:
      • Validates all aspects of the headers/ module, including:
        • Parsing and validation of standard and custom headers.
        • Error handling for malformed or invalid headers.
        • Typed headers and extensions.
    • static/: Ensures proper handling of static file serving and directory listings.
    • hijack/: Tests advanced request hijacking logic for robustness.

Related: #2008

Pre-launch Checklist

  • I read the Contribute page and followed the process outlined there for submitting PRs.
  • This update contains only one single feature or bug fix and nothing else. (If you are submitting multiple fixes, please make multiple PRs.)
  • I read and followed the Dart Style Guide and formatted the code with dart format.
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///), and made sure that the documentation follows the same style as other Serverpod documentation. I checked spelling and grammar.
  • I added new tests to check the change I am making.
  • All existing and new tests are passing.
  • Any breaking changes are documented below.

If you need help, consider asking for advice on the discussion board.

Breaking changes

If you have done any breaking changes, make sure to outline them here, so that they can be included in the notes for the next release.

@vlidholt

vlidholt commented Sep 12, 2024 •

Copy link
Copy Markdown
Collaborator

Some notes for the review. We are primarily focusing on the code in the new relic package. The relic package is based on Dart Shelf, but with adding type safety, properties in HTTP headers, and improved Request and Response objects.

The changes in Serverpod's webserver (within the serverpod package) are just to make sure everything still works. The interface for these will be improved upon in the next set of PRs.

For parts of the review, it may be good to use shelf as a reference.

@klkucaj
klkucaj force-pushed the improvement/rfc branch 3 times, most recently from f4e9bf0 to eda5d4e Compare September 13, 2024 13:01

@vlidholt vlidholt left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work on this one! Lot's of great updates. I did a quick pass, but I think we'll need a second pair of eyes on this one.

There are some things that need to be fixed throughout the PR:

  • There still may be code in here that is no longer used.
  • A lot of the documentation is outdated. It need to be brought up to par with all the changes that have been made.
  • There is a lot of missing documentation. I suggest that we do a second PR for this, once this one has been merged, where we move to the Serverpod linting rules (which also requires docs for everything).

There are also changes that will need to be made to the Serverpod side of things in this PR, but it may be better to do a review of that when we implement the improved routing.

Comment thread packages/relic/.gitignore Resolved
Comment thread packages/relic/analysis_options.yaml Resolved
Comment thread packages/relic/lib/relic.dart Resolved
Comment thread packages/relic/lib/relic_server.dart Resolved
Comment thread packages/relic/lib/src/util/util.dart Resolved
Comment thread packages/relic/lib/src/util/util.dart Resolved
Comment thread packages/relic/test/ssl_certs.dart Resolved

@hampuslavin hampuslavin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some initial comments, will have to do a second pass to dig into some more details 👍

Comment thread packages/relic/analysis_options.yaml Resolved
Comment thread packages/relic/lib/relic_server.dart Resolved
Comment thread packages/relic/lib/relic_server.dart Resolved
Comment thread packages/relic/lib/relic_server.dart Resolved
Comment thread packages/relic/lib/relic_server.dart Resolved
Comment thread packages/relic/lib/src/body.dart Resolved
Comment thread packages/relic/lib/src/headers.dart Resolved
@klkucaj
klkucaj force-pushed the improvement/rfc branch 6 times, most recently from d7e34ba to 604984d Compare September 23, 2024 07:11

@SandPod SandPod left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still a couple of things to fix. There where a couple of comments from the review that where resolved that where not fixed in the PR.

Please read through the comments carefully to ensure that the feedback corresponds to the fix.

Comment thread packages/serverpod/pubspec.yaml Resolved
Comment thread packages/relic/pubspec.yaml Resolved

@SandPod SandPod left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still a couple of comments and suggestions.

@SandPod SandPod left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor comments but I think we are getting there.
Let's have a call for the last fixes.

… and 'set_cookie_header.dar' and also put the name and value validation functions in a separete file called 'cookie_util.dart' under 'util' folder
@SandPod

SandPod commented Dec 13, 2024

Copy link
Copy Markdown
Contributor

This PR was merged as an initial commit to a standalone git repository containing only the Relic web server.
This is the PR that copies over the changes in this branch: serverpod/relic#3

@SandPod SandPod closed this Dec 13, 2024
@github-actions github-actions Bot locked and limited conversation to collaborators Dec 13, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants