Fix regex capture when using map directive and rewrite
Corentin REGAL
corentin.regal at gmail.com
Mon Sep 28 11:54:51 UTC 2020
Hello,
I didn't receive any reply, is there something wrong with the patch ?
If more context is needed, I want to rewrite an url depending on the
Content-Type header.
Regards.
Le jeu. 17 sept. 2020 à 10:39, Corentin REGAL <corentin.regal at gmail.com> a
écrit :
> 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 at 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx-devel/attachments/20200928/db6b5e08/attachment.htm>
More information about the nginx-devel
mailing list