-
-
Notifications
You must be signed in to change notification settings - Fork 92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Setting SCRIPT_NAME environment variable when mounting Rack apps #87
Comments
There is a PR by @cyphactor that should fix this problem directly into If there isn't a quick merge and release of @cyphactor It would be really helpful if you can port it here. Thank you very much! |
I still haven't seen any movement on the http_router PR (joshbuddy/http_router#43) sadly. Hence, I don't expect there to be any movement in terms of getting it merged in and released any time soon. @jodosha I will try to port it to hanami-router today and get a PR up. |
Why you made the change: I made this change so that SCRIPT_NAME and PATH_INFO would be set appropriately in the scenario where a partial match route is used. How the change addresses the need: There is an issue with the current version of rewrite_partial_path_info in HttpRouter where it does not set SCRIPT_NAME appropriately. When the request environments PATH_INFO is set, it causes the request.rack_request.path_info helper return the updated version, not the original. This is requst.rack_request.path_info eventually just reads the PATH_INFO value out of the request environment. As a side effect of this, the original code would always set the SCRIPT_NAME to "" because it would be slicing from request.rack_request.path_info[0, 0] in actuality. This change resolves this issue by first temporarily storing a dup of the original path_info and using that to determine the end index for the SCRIPT_NAME. This change also handles setting SCRIPT_NAME correctly for the somewhat unique but common case of matching the partial match exactly. This change also includes a fix to handle maintaining URI encoded values in PATH_INFO and SCRIPT_INFO. Currently, there is a problem where because the method uses the request.path helper HttpRouter provides, which URI.decodes the string, it screws up both the PATH_INFO and SCRIPT_NAME. Therefore, I URI.encode it back appropriately before any offsetting, or setting is done. I have also added tests for each of these cases as I couldn't find any tests covering this before. This fixes issue hanami#87.
Closed by #91 Thanks to @cyphactor 👏 |
Hey folks. I'm mucking around trying to get Hanami running on Rack 2 and ran into an issue with one of these tests that I thought would be good to bring up. Here's what I found - At and around https://github.com/joshbuddy/http_router/blob/master/lib/http_router/node/path.rb#L32, the behavior of a Rack Request has changed. The salient difference is that in Rack < 2, I took a swing at rewriting the test to capture its intent on my fork; does that seem reasonable? FWIW, I think this is a non-issue if this logic moves upstream to http_router. Meta-level question: would y'all be up for bumping to |
@jamesdabbs Thanks for having a look at this issue with Rack 2. The ideal scenario would be to support Rack >= 1.6 (so 2.0 is included). The improved spec in your fork makes sense, but we should find a way to make it to pass for both Rack versions. At this point backward compat is more important than Rack 2. This because we have more Ruby web apps still running on Rack 1.6 (see Rails 4, Hanami etc..) than Rack 2 (Rails 5). If Rack 2 requires a deep intervention on |
@jamesdabbs when you say " Duping rack requests is a common way of protecting things to support multi-threading. It is also used at the rack middleware/app level for the same reason. I am not sure that is the reason in this particular case but possibility worth exploring. http://stackoverflow.com/questions/23028226/rack-middleware-and-thread-safety |
When I setup Sidekiq with Hanami I ran into an issue when mounting the Sidekiq web interface within an applications route or the container. All URLs for links and assets in Sidekiq were broken because they pointed to the root of my Hanami application even if I mounted it at
/sidekiq
for example.Turns out Sidekiq uses
SCRIPT_NAME
to build its URLs and it seems that Hanami only sets it for Hanami apps and not Rack apps in general.Reading the Rack specification I think Hanami should set
SCRIPT_NAME
accordingly.Rack::URLMap
does it too for example.What do you think?
The text was updated successfully, but these errors were encountered: