Skip to content

Conversation

@rymsha
Copy link
Contributor

@rymsha rymsha commented Dec 29, 2025

No description provided.

@rymsha rymsha linked an issue Dec 29, 2025 that may be closed by this pull request
@rymsha rymsha requested a review from Copilot January 14, 2026 15:35
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR optimizes the URL rewriting logic in the virtual host handling code. The changes improve performance by streamlining the URI rewriting algorithm and eliminating redundant operations.

Changes:

  • Refactored VirtualHostIdProvidersMapping to use ImmutableSet and eliminate duplicate storage of the default ID provider
  • Optimized rewriteUri method with more efficient string matching and path handling logic
  • Added comprehensive test coverage for edge cases including trivial vhost configurations and short URI scenarios

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
VirtualHostIdProvidersMapping.java Simplified data structure by storing default ID provider only once in the ID provider keys set using ImmutableSet.Builder
ServletRequestUrlHelper.java Refactored URL rewriting logic with optimized string operations, modern Java switch expressions, and improved path normalization
ServletRequestUrlHelperTest.java Added new test cases for trivial vhost configurations and edge cases with short URIs

Comment on lines +14 to +15
this.idProviderKeys = IdProviderKeys.from(
ImmutableSet.<IdProviderKey>builder().add( builder.defaultIdProvider ).addAll( builder.idProviderKeys.build() ).build() );
Copy link

Copilot AI Jan 14, 2026

Choose a reason for hiding this comment

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

Potential NullPointerException if builder.defaultIdProvider is null. The .add() method on ImmutableSet.Builder will throw an NPE if passed a null value. Consider validating that defaultIdProvider is not null before adding it, or use appropriate null-safe handling.

Copilot uses AI. Check for mistakes.

final Iterable<String> parts = Splitter.on( '/' ).trimResults().omitEmptyStrings().split( value );
return "/" + String.join( "/", parts );
return Splitter.on( '/' ).omitEmptyStrings().trimResults().splitToStream( path ).collect( Collectors.joining( "/", "/", "" ) );
Copy link

Copilot AI Jan 14, 2026

Choose a reason for hiding this comment

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

The normalizePath method produces paths with trailing slashes (e.g., /path/to/page/ instead of /path/to/page). The Collectors.joining call uses "/" as suffix, which adds a trailing slash to all normalized paths. This differs from the previous implementation which didn't add trailing slashes. This breaking change could affect path matching and routing logic.

Copilot uses AI. Check for mistakes.
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.

Optimize urlRewrite

2 participants