Welcome! Log In Create A New Profile

Advanced

Fix regex capture when using map directive and rewrite

Corentin REGAL
September 17, 2020 04:42AM
Hello,

I fixed a bug when using map directive and rewrite.
Captured variables in the map directive override captures of the rewrite.

*nginx.conf*
daemon off;
error_log /var/log/nginx/error.log debug;
worker_processes 1;
events {
worker_connections 1024;
}

http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 0;

map $http_content_type $input_type {
default json;
~image/ image;
}

server {
server_name localhost;
listen 80;
location / {
rewrite "/(.+)" /$1_${input_type} redirect;
}
}
}


*before patch (/_image)*
curl -v -H'Content-Type: image/png' localhost:80/predict
....
< Location: http://localhost/_image
....

*after patch (/predict_image)*
curl -v -H'Content-Type: image/png' localhost:80/predict
....
< Location: http://localhost/predict_image
....

*patch*
# HG changeset patch
# User Corentin Regal <corentin.regal@gmail.com>
# Date 1600329166 0
# Thu Sep 17 07:52:46 2020 +0000
# Node ID a065d5f865e90a7426d37b30a9faa72e0966756f
# Parent 052ecc68d35038b1b4adde12efe6249a92055f09
Fix ngx_http_map_find to not erase rewrite captures

diff -r 052ecc68d350 -r a065d5f865e9 src/http/ngx_http_variables.c
--- a/src/http/ngx_http_variables.c Wed Sep 16 18:26:25 2020 +0300
+++ b/src/http/ngx_http_variables.c Thu Sep 17 07:52:46 2020 +0000
@@ -2410,7 +2410,7 @@

for (i = 0; i < map->nregex; i++) {

- n = ngx_http_regex_exec(r, reg[i].regex, match);
+ n = ngx_regex_exec(reg[i].regex->regex, match, NULL, 0);

if (n == NGX_OK) {
return reg[i].value;

It's my first time using Mercurial or a mailing list, I hope I did it right
:)

Regards,

Corentin
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

Fix regex capture when using map directive and rewrite

Corentin REGAL 143 September 17, 2020 04:42AM

Re: Fix regex capture when using map directive and rewrite

Corentin REGAL 18 September 28, 2020 07:56AM

Re: Fix regex capture when using map directive and rewrite

Maxim Dounin 27 September 28, 2020 09:56AM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 78
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready