Skip to content

Added pass_subrequest_uri option #118

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 44 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ Example:

tnt_pass_http_request
---------------------
**syntax:** *tnt_pass_http_request [on|off|parse_args|unescape|pass_body|pass_headers_out|parse_urlencoded]*
**syntax:** *tnt_pass_http_request [on|off|parse_args|unescape|pass_body|pass_headers_out|parse_urlencoded|pass_subrequest_uri]*

**default:** *off*

Expand Down Expand Up @@ -599,6 +599,49 @@ Examples #3 (parse_urlencoded):
end
```

Examples #4 (pass_subrequest_uri):

* Origin (unparsed) uri
```nginx
location /web {
# Backend processing /web/foo and replying with X-Accel-Redirect to
# internal /tnt/bar
proxy_pass http://x-accel-redirect-backend;
}
location /tnt {
internal;
tnt_pass_http_request on;
tnt_method tarantool_xar_handler;
tnt_pass 127.0.0.1:9999;
}
```
```lua
function tarantool_xar_handler(req, ...)
print(req.uri) -- /web/foo
return true
end
```
* Subrequest uri
```nginx
location /web {
# Backend processing /web/foo and replying with X-Accel-Redirect to
# internal /tnt/bar
proxy_pass http://x-accel-redirect-backend;
}
location /tnt {
internal;
tnt_pass_http_request on pass_subrequest_uri;
tnt_method tarantool_xar_handler;
tnt_pass 127.0.0.1:9999;
}
```
```lua
function tarantool_xar_handler(req, ...)
print(req.uri) -- /tnt/bar
return true
end
```

```bash
# Call tarantool_stored_procedure_name()
$> wget NGINX_HOST/tarantool_stored_procedure_name/some/mega/path?q=1&q=2&q=3
Expand Down
27 changes: 17 additions & 10 deletions src/ngx_http_tnt_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,14 @@


typedef enum ngx_tnt_conf_states {
NGX_TNT_CONF_ON = 1,
NGX_TNT_CONF_OFF = 2,
NGX_TNT_CONF_PARSE_ARGS = 4,
NGX_TNT_CONF_UNESCAPE = 8,
NGX_TNT_CONF_PASS_BODY = 16,
NGX_TNT_CONF_PASS_HEADERS_OUT = 32,
NGX_TNT_CONF_PARSE_URLENCODED = 64,
NGX_TNT_CONF_ON = 1,
NGX_TNT_CONF_OFF = 2,
NGX_TNT_CONF_PARSE_ARGS = 4,
NGX_TNT_CONF_UNESCAPE = 8,
NGX_TNT_CONF_PASS_BODY = 16,
NGX_TNT_CONF_PASS_HEADERS_OUT = 32,
NGX_TNT_CONF_PARSE_URLENCODED = 64,
NGX_TNT_CONF_PASS_SUBREQUEST_URI = 128,
} ngx_tnt_conf_states_e;


Expand Down Expand Up @@ -427,6 +428,7 @@ static ngx_conf_bitmask_t ngx_http_tnt_pass_http_request_masks[] = {
{ ngx_string("pass_body"), NGX_TNT_CONF_PASS_BODY },
{ ngx_string("pass_headers_out"), NGX_TNT_CONF_PASS_HEADERS_OUT },
{ ngx_string("parse_urlencoded"), NGX_TNT_CONF_PARSE_URLENCODED },
{ ngx_string("pass_subrequest_uri"), NGX_TNT_CONF_PASS_SUBREQUEST_URI },
{ ngx_null_string, 0 }
};

Expand Down Expand Up @@ -3166,13 +3168,18 @@ ngx_http_tnt_get_request_data(ngx_http_request_t *r,
goto oom_cant_encode;
}

/** Encode raw uri */
/** Encode uri:
* whether NGX_TNT_CONF_PASS_SUBREQUEST_URI is not set then raw uri
* will be chosen, otherwise preprocessed value will be used
*/
++root_items;

ngx_str_t uri = tlcf->pass_http_request & NGX_TNT_CONF_PASS_SUBREQUEST_URI
? r->uri : r->unparsed_uri;

if (ngx_http_tnt_encode_str_map_item(r, tlcf, tp,
(u_char *) "uri", sizeof("uri") - 1,
r->unparsed_uri.data,
r->unparsed_uri.len) == NGX_ERROR)
uri.data, uri.len) == NGX_ERROR)
{
goto oom_cant_encode;
}
Expand Down
2 changes: 1 addition & 1 deletion src/ngx_http_tnt_version.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@
#ifndef NGX_HTTP_TNT_VERSION_H
#define NGX_HTTP_TNT_VERSION_H 1

#define NGX_HTTP_TNT_MODULE_VERSION_STRING "v2.5-rc4"
#define NGX_HTTP_TNT_MODULE_VERSION_STRING "v2.7"

#endif