Enhancement for Router to ignore double slashes?

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Enhancement for Router to ignore double slashes?

Avi Flax
Hi everyone!

Currently, if one creates a route like this:

router.attach("books/{book}", BookResource.class);

and then sends a request like this:

GET books//some_book

the response is a 404; the Router, Route, and Template classes consult
each other and determine that the requested path is not defined,
because of the double slashes.

This behaviour makes sense, but I'm interested in a way to put the
Router or the Route into a mode wherein they would ignore the double
slashes somehow, or collapse them together into a single slash. I
tried to follow the Routing code but I couldn't figure it out.

So my question: would there be interest in an enhancement such as
this? Or does anyone have a suggestion on how to achieve this via
filters or services or something like that?

Thanks!

--
Avi Flax » Lead Technologist » Partner » Arc90 » http://arc90.com
Reply | Threaded
Open this post in threaded view
|

Re: Enhancement for Router to ignore double slashes?

Avi Flax
On Mon, Nov 3, 2008 at 19:09, Avi Flax <[hidden email]> wrote:

> ...I'm interested in a way to put the
> Router or the Route into a mode wherein they would ignore the double
> slashes somehow, or collapse them together into a single slash. I
> tried to follow the Routing code but I couldn't figure it out.
>
> So my question: would there be interest in an enhancement such as
> this? Or does anyone have a suggestion on how to achieve this via
> filters or services or something like that?

Not much interest in this, apparently, which is fine, but I'm still
interested, so I'll keep going.

I've figured out how to have a Filter, placed in the chain before a
Router, remove double-slashes:

@Override
protected int beforeHandle(Request request, Response response) {
        Reference ref = request.getResourceRef();
       
        String originalPath = ref.getPath();
       
        if (originalPath.contains("//"))
        {
                String newPath = originalPath.replaceAll("//", "/");
                ref.setPath(newPath);
        }
       
        return Filter.CONTINUE;
}

This works just fine. (I know the regex should probably be more
sophisticated, but this is more about a proof of concept than
production-ready code.) But I'd be interested in having this
functionality be built into the framework; using a syntax something
like:

router.setIgnoreDoubleSlashes(true);

or maybe:

router.setIgnoreCommonTypos(true);

So I'll ask one more time: would anyone else like to see this feature
make it into the API?

--
Avi Flax » Lead Technologist » Partner » Arc90 » http://arc90.com
Reply | Threaded
Open this post in threaded view
|

Re: Enhancement for Router to ignore double slashes?

Rob Heittman
Musing (without any ability to code and see right this second) ...

I use Reference.getTargetRef() a lot for normalization purposes ... and if it doesn't already do so, there has at least been discussion of making getTargetRef() elide stuff like /foo/../bar to /bar, /foo/./bar to /foo/bar, or /foo//bar to /foo/bar.  I think the API feature that might make sense is one that uses getTargetRef() to normalize all such things to a canonical reference before routing -- not just //.

On Wed, Nov 5, 2008 at 3:27 PM, Avi Flax <[hidden email]> wrote:
So I'll ask one more time: would anyone else like to see this feature
make it into the API?

Reply | Threaded
Open this post in threaded view
|

Re: Enhancement for Router to ignore double slashes?

Avi Flax
On Wed, Nov 5, 2008 at 15:42, Rob Heittman <[hidden email]> wrote:

> I use Reference.getTargetRef() a lot for normalization purposes ... and if
> it doesn't already do so, there has at least been discussion of making
> getTargetRef() elide stuff like /foo/../bar to /bar, /foo/./bar to /foo/bar,
> or /foo//bar to /foo/bar.  I think the API feature that might make sense is
> one that uses getTargetRef() to normalize all such things to a canonical
> reference before routing -- not just //.

Makes sense to me! But do Router/Route/Template currently use
Reference.getTargetRef() as part of their normal operation, when
trying to match a request URL to a Route? If not, that might be a
pretty significant change to some core code.
Reply | Threaded
Open this post in threaded view
|

Re: Enhancement for Router to ignore double slashes?

Rob Heittman
I exist to create work for Jerome and Thierry.
 
Makes sense to me! But do Router/Route/Template currently use
Reference.getTargetRef() as part of their normal operation, when
trying to match a request URL to a Route? If not, that might be a
pretty significant change to some core code.

Reply | Threaded
Open this post in threaded view
|

RE: Enhancement for Router to ignore double slashes?

jlouvel
Administrator
Hi guys,
 
This is definitely an interesting suggestion Avi! I do like Rob's generic solution as well:
 
"Automatically normalize URIs"
 
See my comments inside the RFE and let's discuss the design details there maybe.
 
Best regards,
Jérôme Louvel
--
Restlet ~ Founder and Lead developer ~
http://www.restlet.org
Noelios Technologies ~ Co-founder ~ http://www.noelios.com


De : Rob Heittman [mailto:[hidden email]]
Envoyé : mercredi 5 novembre 2008 21:49
À : [hidden email]
Objet : Re: Enhancement for Router to ignore double slashes?

I exist to create work for Jerome and Thierry.
 
Makes sense to me! But do Router/Route/Template currently use
Reference.getTargetRef() as part of their normal operation, when
trying to match a request URL to a Route? If not, that might be a
pretty significant change to some core code.