Getting rewritten and encoded/escaped url in nginx module

Jayadev C jayadev at ymail.com
Tue Jun 3 21:08:36 UTC 2014



The problem is ngx_http_proxy doesn't do that either, once rewrite is applied the url remains decoded (or I am not reading the code correctly).  In fact escaping uri back is a bit tricky since you have to split the rewritten url to segments and apply encoding again (which would require looking at the original url to know the correct number of '/'s).


Anybody had attempted doing something like this ? or is there an easier way.

Jayadev



On Tuesday, June 3, 2014 10:17 AM, Maxim Dounin <mdounin at mdounin.ru> wrote:
 


Hello!

On Tue, Jun 03, 2014 at 09:42:41AM -0700, Jayadev C wrote:

> 
> 
> Hi, 
> 
> 
> I am writing a nginx proxy module and want to grab the url which 
> is urlencoded (as the client sends it) and also after rewrite 
> rules are applied.  My typical url looks like : 
> path1/path2/path3/urlencoded(key)?args, after rewriting the url 
> I would love to have is something like :
> 
> newpath1/newpath2/newpath3/../urlencoded(key)?args.
> 
> Currently , r->uri  is decoded rewritten uri, r->unparsed_uri is 
> encoded but not rewritten.
> 
> I read on the forum that nginx decodes the url for rewrite, is 
> there a handy internal function I can use encode the rewritten 
> url back. A simple use of ngx_escape_uri(r->uri) with different 
> parameters doesn't do what I want out of the box. 

The ngx_escape_uri(r->uri) _is_ the internal function you should 
use if you need encoded URI.

If in doubt, try looking, e.g., into the ngx_http_proxy_create_request() 
function to see how it's done there.

-- 
Maxim Dounin
http://nginx.org/


_______________________________________________
nginx mailing list
nginx at nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20140603/33feb38c/attachment-0001.html>


More information about the nginx mailing list