Skip to content

Commit

Permalink
Merge pull request #118 from igormunkin/master
Browse files Browse the repository at this point in the history
Added `pass_subrequest_uri` option
  • Loading branch information
dedok committed Jul 23, 2018
2 parents 1e90435 + 1dc473b commit 6c5696b
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 12 deletions.
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

0 comments on commit 6c5696b

Please sign in to comment.