Skip to content

Commit 6c5696b

Browse files
authored
Merge pull request #118 from igormunkin/master
Added `pass_subrequest_uri` option
2 parents 1e90435 + 1dc473b commit 6c5696b

File tree

3 files changed

+62
-12
lines changed

3 files changed

+62
-12
lines changed

README.md

+44-1
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ Example:
512512

513513
tnt_pass_http_request
514514
---------------------
515-
**syntax:** *tnt_pass_http_request [on|off|parse_args|unescape|pass_body|pass_headers_out|parse_urlencoded]*
515+
**syntax:** *tnt_pass_http_request [on|off|parse_args|unescape|pass_body|pass_headers_out|parse_urlencoded|pass_subrequest_uri]*
516516

517517
**default:** *off*
518518

@@ -599,6 +599,49 @@ Examples #3 (parse_urlencoded):
599599
end
600600
```
601601

602+
Examples #4 (pass_subrequest_uri):
603+
604+
* Origin (unparsed) uri
605+
```nginx
606+
location /web {
607+
# Backend processing /web/foo and replying with X-Accel-Redirect to
608+
# internal /tnt/bar
609+
proxy_pass http://x-accel-redirect-backend;
610+
}
611+
location /tnt {
612+
internal;
613+
tnt_pass_http_request on;
614+
tnt_method tarantool_xar_handler;
615+
tnt_pass 127.0.0.1:9999;
616+
}
617+
```
618+
```lua
619+
function tarantool_xar_handler(req, ...)
620+
print(req.uri) -- /web/foo
621+
return true
622+
end
623+
```
624+
* Subrequest uri
625+
```nginx
626+
location /web {
627+
# Backend processing /web/foo and replying with X-Accel-Redirect to
628+
# internal /tnt/bar
629+
proxy_pass http://x-accel-redirect-backend;
630+
}
631+
location /tnt {
632+
internal;
633+
tnt_pass_http_request on pass_subrequest_uri;
634+
tnt_method tarantool_xar_handler;
635+
tnt_pass 127.0.0.1:9999;
636+
}
637+
```
638+
```lua
639+
function tarantool_xar_handler(req, ...)
640+
print(req.uri) -- /tnt/bar
641+
return true
642+
end
643+
```
644+
602645
```bash
603646
# Call tarantool_stored_procedure_name()
604647
$> wget NGINX_HOST/tarantool_stored_procedure_name/some/mega/path?q=1&q=2&q=3

src/ngx_http_tnt_module.c

+17-10
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,14 @@
4343

4444

4545
typedef enum ngx_tnt_conf_states {
46-
NGX_TNT_CONF_ON = 1,
47-
NGX_TNT_CONF_OFF = 2,
48-
NGX_TNT_CONF_PARSE_ARGS = 4,
49-
NGX_TNT_CONF_UNESCAPE = 8,
50-
NGX_TNT_CONF_PASS_BODY = 16,
51-
NGX_TNT_CONF_PASS_HEADERS_OUT = 32,
52-
NGX_TNT_CONF_PARSE_URLENCODED = 64,
46+
NGX_TNT_CONF_ON = 1,
47+
NGX_TNT_CONF_OFF = 2,
48+
NGX_TNT_CONF_PARSE_ARGS = 4,
49+
NGX_TNT_CONF_UNESCAPE = 8,
50+
NGX_TNT_CONF_PASS_BODY = 16,
51+
NGX_TNT_CONF_PASS_HEADERS_OUT = 32,
52+
NGX_TNT_CONF_PARSE_URLENCODED = 64,
53+
NGX_TNT_CONF_PASS_SUBREQUEST_URI = 128,
5354
} ngx_tnt_conf_states_e;
5455

5556

@@ -427,6 +428,7 @@ static ngx_conf_bitmask_t ngx_http_tnt_pass_http_request_masks[] = {
427428
{ ngx_string("pass_body"), NGX_TNT_CONF_PASS_BODY },
428429
{ ngx_string("pass_headers_out"), NGX_TNT_CONF_PASS_HEADERS_OUT },
429430
{ ngx_string("parse_urlencoded"), NGX_TNT_CONF_PARSE_URLENCODED },
431+
{ ngx_string("pass_subrequest_uri"), NGX_TNT_CONF_PASS_SUBREQUEST_URI },
430432
{ ngx_null_string, 0 }
431433
};
432434

@@ -3166,13 +3168,18 @@ ngx_http_tnt_get_request_data(ngx_http_request_t *r,
31663168
goto oom_cant_encode;
31673169
}
31683170

3169-
/** Encode raw uri */
3171+
/** Encode uri:
3172+
* whether NGX_TNT_CONF_PASS_SUBREQUEST_URI is not set then raw uri
3173+
* will be chosen, otherwise preprocessed value will be used
3174+
*/
31703175
++root_items;
31713176

3177+
ngx_str_t uri = tlcf->pass_http_request & NGX_TNT_CONF_PASS_SUBREQUEST_URI
3178+
? r->uri : r->unparsed_uri;
3179+
31723180
if (ngx_http_tnt_encode_str_map_item(r, tlcf, tp,
31733181
(u_char *) "uri", sizeof("uri") - 1,
3174-
r->unparsed_uri.data,
3175-
r->unparsed_uri.len) == NGX_ERROR)
3182+
uri.data, uri.len) == NGX_ERROR)
31763183
{
31773184
goto oom_cant_encode;
31783185
}

src/ngx_http_tnt_version.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,6 @@
3434
#ifndef NGX_HTTP_TNT_VERSION_H
3535
#define NGX_HTTP_TNT_VERSION_H 1
3636

37-
#define NGX_HTTP_TNT_MODULE_VERSION_STRING "v2.5-rc4"
37+
#define NGX_HTTP_TNT_MODULE_VERSION_STRING "v2.7"
3838

3939
#endif

0 commit comments

Comments
 (0)