Skip to content

refactor!: Remove automatic X-Powered-By header - #169

Merged
nielsenko merged 2 commits into
serverpod:mainfrom
nielsenko:remove-x-powered-by
Sep 19, 2025
Merged

nielsenko merged 2 commits into
serverpod:mainfrom
nielsenko:remove-x-powered-by

Conversation

@nielsenko

@nielsenko nielsenko commented Sep 15, 2025 •

Copy link
Copy Markdown
Collaborator

Description

The serve() function no longer accepts a poweredByHeader parameter and Relic no longer automatically sets the X-Powered-By header on responses.

Users who want this header can set it manually using middleware or by setting it directly on Response objects.

Related Issues

Pre-Launch Checklist

Please ensure that your PR meets the following requirements before submitting:

  • This update focuses on a single feature or bug fix. (For multiple fixes, please submit separate PRs.)
  • I have read and followed the Dart Style Guide and formatted the code using dart format.
  • I have referenced at least one issue this PR fixes or is related to.
  • I have updated/added relevant documentation (doc comments with ///), ensuring consistency with existing project documentation.
  • I have added new tests to verify the changes.
  • All existing and new tests pass successfully.
  • I have documented any breaking changes below.

Breaking Changes

  • Includes breaking changes.
  • No breaking changes.

The serve() function no longer accepts a poweredByHeader parameter

Summary by CodeRabbit

  • Refactor
    • Removed automatic injection of the X-Powered-By header; only a Date header is ensured by default.
    • Removed server-level configuration for a default X-Powered-By value; set it manually per response if needed.
  • Documentation
    • Updated header defaults description to reflect the removal of X-Powered-By behavior.
  • Tests
    • Adjusted tests to expect no default X-Powered-By header and to validate manual header setting via response headers.

@coderabbitai

coderabbitai Bot commented Sep 15, 2025 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

📝 Walkthrough

Walkthrough

Removes support for configuring or auto-injecting the X-Powered-By header. Updates RelicServer and serve API to drop the poweredByHeader parameter and related constants/fields. Middleware now only ensures a Date header. Tests are updated to reflect absence of automatic X-Powered-By and to use per-response headers when needed.

Changes

Cohort / File(s) Summary
IO serve API
lib/src/adapter/io/io_serve.dart
Dropped named parameter poweredByHeader from serve; removed forwarding to RelicServer; updated header defaults comment to only mention Date.
Server core: header injection removal
lib/src/relic_server.dart
Removed defaultPoweredByHeader constant and poweredByHeader field; constructor no longer accepts poweredByHeader; middleware now only ensures Date header.
Tests: X-Powered-By behavior
test/relic_server_serve_test.dart, test/headers/basic/x_powered_by_header_test.dart
Updated expectations to no automatic X-Powered-By; removed server-level config scenarios; added direct header accessor tests and preservation via response headers.
Test utilities
test/util/test_util.dart
Dropped poweredByHeader parameter from testServe and its forwarding to serve.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant C as Client
  participant S as RelicServer
  participant H as Handler

  C->>S: HTTP Request
  S->>H: Invoke handler
  H-->>S: Response (may include headers)
  rect rgba(200,230,255,0.3)
    note over S: Header normalization
    S->>S: Ensure Date header if missing
    note over S: No X-Powered-By injection
  end
  S-->>C: HTTP Response
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Title Check ✅ Passed The title "refactor!: Remove automatic X-Powered-By header" is concise and directly describes the primary change in the PR — removal of automatic X-Powered-By behavior — and the "!" marker appropriately signals a breaking change; it maps clearly to the modified serve() signature, RelicServer constructor, and test updates. The phrasing is specific, readable, and suitable for changelogs and review.
Linked Issues Check ✅ Passed The changes satisfy issue #165's goals: automatic X-Powered-By injection was removed (default constant and poweredByHeader field deleted), serve() no longer accepts a poweredByHeader parameter, and tests/utilities were updated to expect no automatic header, which prevents inadvertent server fingerprinting while allowing deliberate addition via middleware. The implementation and test updates align directly with the linked issue's intent.
Out of Scope Changes Check ✅ Passed All modifications in the provided summaries are focused on removing the automatic X-Powered-By header and the related API/test surfaces; test adjustments and utility signature updates are consistent with that scope and I see no unrelated features or refactors introduced. The changes appear limited to serve(), RelicServer, tests, and test utilities as expected.
Description Check ✅ Passed The PR description follows the repository template by providing a clear Description of the change, linking the related issue (Fixes #165), including a completed Pre-Launch Checklist, and documenting the breaking change (serve() no longer accepts poweredByHeader). The author also states tests and docs were updated. All required template sections are present and sufficiently filled.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov

codecov Bot commented Sep 15, 2025 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.76%. Comparing base (acef84f) to head (f6e7536).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #169      +/-   ##
==========================================
- Coverage   91.77%   91.76%   -0.01%     
==========================================
  Files          85       85              
  Lines        3123     3122       -1     
  Branches     1618     1618              
==========================================
- Hits         2866     2865       -1     
  Misses        257      257              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@nielsenko

Copy link
Copy Markdown
Collaborator Author

@CodeRabbit review

@coderabbitai

coderabbitai Bot commented Sep 15, 2025

Copy link
Copy Markdown
Contributor
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@nielsenko nielsenko self-assigned this Sep 15, 2025

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

🧹 Nitpick comments (2)
lib/src/relic_server.dart (1)

116-123: Use UTC for Date header generation.

HTTP Date must be IMF-fixdate in GMT. Prefer UTC to avoid ambiguity and accidental local‑time emission.

Apply:

-                  mh.date ??= DateTime.now();
+                  mh.date ??= DateTime.now().toUtc();
test/relic_server_serve_test.dart (1)

372-381: Deduplicate with first test.

This repeats “not automatically set” through a different setup path. Consider merging to reduce flakiness/time.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 44378bc and 0077109.

📒 Files selected for processing (5)
  • lib/src/adapter/io/io_serve.dart (1 hunks)
  • lib/src/relic_server.dart (1 hunks)
  • test/headers/basic/x_powered_by_header_test.dart (1 hunks)
  • test/relic_server_serve_test.dart (2 hunks)
  • test/util/test_util.dart (0 hunks)
💤 Files with no reviewable changes (1)
  • test/util/test_util.dart
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-05-23T04:15:01.420Z
Learnt from: nielsenko
PR: serverpod/relic#76
File: lib/src/handler/handler.dart:20-20
Timestamp: 2025-05-23T04:15:01.420Z
Learning: In the relic codebase, ResponseContext is a subtype of HandledContext, making functions with signature ResponseContext Function(RequestContext) assignable to the Handler typedef (FutureOr<HandledContext> Function(NewContext ctx)) due to covariant return types and contravariant parameter types in Dart's type system.

Applied to files:

  • lib/src/relic_server.dart
🔇 Additional comments (6)
test/headers/basic/x_powered_by_header_test.dart (3)

9-16: LGTM: accessor-based validation is clear.

Good pivot away from server defaults; this verifies explicit, opt‑in behavior.


22-31: LGTM: null handling covered.

Confirms header omission semantics when unset.


33-42: LGTM: response preserves explicitly set header.

Covers end-to-end preservation via Response.ok.

test/relic_server_serve_test.dart (3)

350-357: LGTM: no automatic X-Powered-By.

Asserts the new default (absent) correctly.


360-367: LGTM: manual per-response header works.

Verifies explicit opt‑in.


383-391: LGTM: preserves manually set header.

Covers server created via testServe path.

Comment thread lib/src/adapter/io/io_serve.dart Resolved
@nielsenko
nielsenko marked this pull request as ready for review September 17, 2025 11:17
@nielsenko
nielsenko requested a review from a team September 17, 2025 11:17

@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.

LGTM! One question regarding a test.

BREAKING CHANGE: The serve() function no longer accepts a poweredByHeader
parameter and Relic no longer automatically sets the X-Powered-By header
on responses. Users who want this header can set it manually using
middleware or by setting it directly on Response objects.

Fixes serverpod#165
@nielsenko
nielsenko merged commit 07f40e3 into serverpod:main Sep 19, 2025
@coderabbitai coderabbitai Bot mentioned this pull request Sep 19, 2025
7 of 9 tasks
@coderabbitai coderabbitai Bot mentioned this pull request Oct 16, 2025
8 of 9 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Relic should not set x-powered-by

2 participants