Skip to content

[Router] Compose and restore SCRIPT_NAME for mounted Rack apps - #356

Merged
rsamoilov merged 1 commit into
rage-rb:mainfrom
RedZapdos123:fix-router-mounted-script-name-355
Jul 21, 2026
Merged

[Router] Compose and restore SCRIPT_NAME for mounted Rack apps#356
rsamoilov merged 1 commit into
rage-rb:mainfrom
RedZapdos123:fix-router-mounted-script-name-355

Conversation

@RedZapdos123

@RedZapdos123 RedZapdos123 commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Description:

Issue #355 reported that mounted Rack apps overwrite SCRIPT_NAME with only the mount path and do not restore the original value after the mounted app returns.

This PR updates router mount handling to compose SCRIPT_NAME from the existing prefix plus the mount path, while still passing the mounted subpath as PATH_INFO.

It also restores the original SCRIPT_NAME and PATH_INFO after the mounted app returns, adds a regression spec that covers both behaviors, and adds a changelog entry for the fix.

Before the fix:

  • before call: SCRIPT_NAME="/outer", PATH_INFO="/rack_app/index"
  • mounted app saw: SCRIPT_NAME="/rack_app", PATH_INFO="/index"
  • after call: SCRIPT_NAME="/rack_app", PATH_INFO="/rack_app/index"
image

After the fix:

  • before call: SCRIPT_NAME="/outer", PATH_INFO="/rack_app/index"
  • mounted app sees: SCRIPT_NAME="/outer/rack_app", PATH_INFO="/index"
  • after call: SCRIPT_NAME="/outer", PATH_INFO="/rack_app/index"
image

Closes #355.

Checklist:

  • I have run focused tests using bundle exec rspec spec/router/mount_spec.rb.
  • I have run broader router tests using bundle exec rspec spec/router.
  • I have run the full test suite using bundle exec rspec.

Compose SCRIPT_NAME from the existing prefix plus the mount path for mounted Rack apps, and restore the original Rack env values after the mounted app returns.

Signed-off-by: Mridankan Mandal <xerontitan90@gmail.com>

@rsamoilov rsamoilov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks great!

@rsamoilov
rsamoilov merged commit 65ed10b into rage-rb:main Jul 21, 2026
11 checks passed
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.

[Router] Mounted Rack apps do not compose or restore SCRIPT_NAME correctly

2 participants