Skip to content
This repository was archived by the owner on Jul 29, 2024. It is now read-only.
This repository was archived by the owner on Jul 29, 2024. It is now read-only.

UrlMap not interpreting REQUEST_URI correctly #9

Description

@nettles-jarrod

In situations where there is a file prefix in the REQUEST_URI, UrlMap incorrectly includes it as part of the intended route.

For example, in Symfony during development, you usually visit the app through local.dev/app_dev.php/my/action and Symfony is smart enough to compute the /my/action route automatically, chopping off the app_dev.php.

StackPHP does not chop off this file prefix. It seems to me that this should be the expected behavior.

You can easily reproduce this issue by using two middlewares and UrlMap through a file in the URL.

Activity

  1. ghost assigned on Aug 13, 2013
  2. CHH commented on Aug 13, 2013

    @CHH
    Member

    Tested it on the dev server, works for me.

    app_dev.php:

    <?php
    
    require "vendor/autoload.php";
    
    use Stack\CallableHttpKernel;
    use Symfony\Component\HttpFoundation\Request;
    use Symfony\Component\HttpFoundation\Response;
    
    $app = new CallableHttpKernel(function ($req) {
        return new Response("app");
    });
    
    $foo = new CallableHttpKernel(function ($req) {
        return new Response("foo");
    });
    
    $map = new Stack\UrlMap($app, [
        '/foo' => $foo
    ]);
    
    $resp = $map->handle(Request::createFromGlobals());
    $resp->send();

    On the shell:

    $ php -S localhost:4000 -t ./
    

    Request in the browser: http://localhost:4000/app_dev.php/foo and you should get "foo"

    Make sure that you request this code really through app_dev.php. It doesn't work if app_dev.php is not a real script and the "app_dev.php" is not the basename of the script filename. We can't do anything about this, it's all handled internally by the request object.

  3. nettles-jarrod commented on Aug 13, 2013

    @nettles-jarrod
    Author

    Your example works correctly, but I invite you to try it with Stack\Builder and a fresh Symfony install.

    There's either a problem, or the documentation isn't clear enough on how to handle this.

  4. CHH commented on Aug 13, 2013

    @CHH
    Member

    Ok, looking into it.

    Am Dienstag, 13. August 2013 schrieb Jarrod Nettles :

    Your example works, but I invite you to try it with Stack\Builder and a
    fresh Symfony install.

    There's either a problem, or the documentation isn't clear enough on how
    to handle this.

    —
    Reply to this email directly or view it on GitHubhttps://github.com//issues/9#issuecomment-22580791
    .

    Christoph Hochstrasser
    http://twitter.com/yuri41 | http://christophh.net | https://github.com/CHH

  5. igorw commented on Aug 13, 2013

    @igorw
    Contributor

    Re-opening, just so this does not get lost.

  6. reopened this on Aug 13, 2013
  7. defrag commented on Aug 20, 2013

    @defrag

    I had to use it today and I confirm that the issue exists. In my app, when i access site via app_dev.php,
    i had to change server variables in handle to make it work with app_dev.php to:

       $server['SCRIPT_FILENAME'] = $server['SCRIPT_NAME'] = $server['PHP_SELF'] = $server['SCRIPT_NAME'] . $path;

    cc @Blackshawk

  8. CHH commented on Aug 20, 2013

    @CHH
    Member

    @defrag Could you please post the complete file with your code?

  9. CHH commented on Aug 20, 2013

    @CHH
    Member

    @Blackshawk:
    I've now tried it with Symfony 2.3 Components and Stack Builder and it works without problems on the builtin dev server.

    What web server are you using?

    Here is my code:

    <?php
    
    require "vendor/autoload.php";
    
    use Stack\CallableHttpKernel;
    use Symfony\Component\HttpFoundation\Request;
    use Symfony\Component\HttpFoundation\Response;
    use Stack\UrlMap;
    use Stack\Builder;
    
    $app = new CallableHttpKernel(function ($req) {
        return new Response("app");
    });
    
    $foo = new CallableHttpKernel(function ($req) {
        echo "<pre>";
        print_r($_SERVER);
        echo "</pre>";
        return new Response("foo");
    });
    
    $app = (new Builder)
        ->push(UrlMap::class, [
            '/foo' => $foo
        ])
        ->resolve($app);
    
    $resp = $app->handle(Request::createFromGlobals());
    $resp->send();
  10. CHH commented on Aug 20, 2013

    @CHH
    Member

    @Blackshawk: Will try it with a fresh Symfony install too.

  11. CHH commented on Aug 20, 2013

    @CHH
    Member

    @Blackshawk: Tried it with a completely fresh Symfony 2.3 install and it works with ./app/console server:run.

    I added only this to my app_dev.php:

    <?php
    
    $kernel = (new Stack\Builder)
        ->push(Stack\UrlMap::class, [
            '/foo' => new Stack\CallableHttpKernel(function ($req) {
                return new Response("foo");
            })
        ])
        ->resolve($kernel);
  12. CHH commented on Aug 20, 2013

    @CHH
    Member

    @defrag @Blackshawk Which web server gives you this issues? Apache, NGINX or the builtin dev server?

  13. defrag commented on Aug 20, 2013

    @defrag

    @CHH Well it will work with the CallableHttpKernel with simple response like you showed, but it will not work with symfony2 app kernel. In my case I have FeatureKernel that extends AppKernel, which have some associated webservices that needs to be mock per feature.

    foreach ($fakeWs as $key => $value) {
        $map['/' . $key] = $featureKernel;
    }
    
    $stack = (new Stack\Builder)
        ->push('Stack\UrlMap', $map)
    ;

    Then im accessing page like app_dev.php/FEATURE-123/ and it boots kernel with needed data.

    If i will not change the server variables like I mentioned in sample before, all routings etc will totally mess. Try mapping new AppKernel instead of CallableHttpKernel and You will see errors.
    Hope that explanation helps. I didnt found the best way to handle this yet, im currently using modified UrlMap.

  14. nettles-jarrod commented on Aug 20, 2013

    @nettles-jarrod
    Author

    @CHH I was using Apache, although I experienced the same problem using the built-in dev server also. I think @defrag is correct - I just tried bootstrapping a Symfony and a Silex kernel and was getting the same behavior. For some reason CallableHttpKernel doesn't exhibit this behavior.

  15. henrikbjorn commented on Feb 5, 2014

    @henrikbjorn
    Contributor

    Have the same problem with lighttpd and fpm.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions