If it's a legacy app then presumably it doesn't use the Plack::Request API. So instead of using that just use a thin wrapper that checks for both $str and $str =~ try/-_/_-/ ?
--
---
You received this message because you are subscribed to the Google Groups "psgi-plack" group.
To unsubscribe from this group and stop receiving emails from it, send an email to psgi-plack+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
mla wrote:
> I'm upgrading a legacy app that is inconsistent with its query parameter
> names. e.g., sometimes "user-id" is used, whereas other times it's
> "user_id". I'd like to normalize the parameter keys to underscores, so
> I don't have to worry about the inconsistencies from the front end,
> but I'm not sure how best to do that.
I use a custom middleware for a similar purpose and thought about a
general Middleware for query string rewriting. Here is a boilerplate:
> > I use a custom middleware for a similar purpose and thought about a
> > general Middleware for query string rewriting. Here is a boilerplate:
>
> Thanks. Yeah, I was hoping to avoid double parsing everything, but that
> might be the simplest. Query and body parameters would end up having
> different rules, which isn't ideal (I mainly care about the query
> parameters but it would be nice to be consistent).
This was on may TODO-List anyway, so I created
Plack::Middleware::Rewrite::Query, just released at CPAN.
To replace all minus with underscore in query parameter names:
builder {
enable 'Rewrite::Query', map => sub { $_[0] =~ s/-/_/g; @_ },
$app;
}