Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -627,16 +627,15 @@ Examples #3 (parse_urlencoded):
function tarantool_stored_procedure_name(req, ...)
req.headers -- a lua table
req.query -- a string
req.body[0]['q'] -- 1
req.body[1]['q'] -- 2
req.body[2]['q'] -- 3
req.args.q -- 1
req.args_urlencoded.p -- 2
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
$> wget NGINX_HOST/tarantool_stored_procedure_name/some/mega/path?q=1 --post-data='p=2'
```

Examples #4 (pass_subrequest_uri):
Expand Down
134 changes: 70 additions & 64 deletions src/ngx_http_tnt_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
* please see AUTHORS file.
*/


#include <ngx_core.h>
#include <ngx_http.h>
#include <ngx_config.h>
Expand Down Expand Up @@ -1615,7 +1616,7 @@ ngx_http_tnt_urldecode(ngx_http_request_t *r, ngx_str_t *src)

c = src->data[s++];

if (c == '%' && (ngx_uint_t) (s + 2) <= src->len) {
if (c == '%' && (ngx_uint_t) (s + 2) < src->len) {

u_char c2 = src->data[s++];
u_char c3 = src->data[s++];
Expand Down Expand Up @@ -3239,98 +3240,103 @@ ngx_http_tnt_get_request_data(ngx_http_request_t *r,
*(uint32_t *) map_place = mp_bswap_u32(map_items);

/** Encode body */
if ((tlcf->pass_http_request & NGX_TNT_CONF_PASS_BODY ||
tlcf->pass_http_request & NGX_TNT_CONF_PARSE_URLENCODED) &&
if ((tlcf->pass_http_request & NGX_TNT_CONF_PARSE_URLENCODED) &&
r->headers_in.content_length_n > 0 &&
r->upstream->request_bufs)
{
++root_items;

if (tp_encode_str(tp, "body", sizeof("body") - 1) == NULL) {
if (tp_encode_str(tp, "args_urlencoded", sizeof("args_urlencoded") - 1) == NULL) {
goto oom_cant_encode_body;
}

/** Encode urlencoded body as map - body = { K = V, .. } */
if (tlcf->pass_http_request & NGX_TNT_CONF_PARSE_URLENCODED) {

map_place = tp->p;
map_place = tp->p;

if (tp_add(tp, 1 + sizeof(uint32_t)) == NULL) {
goto oom_cant_encode_body;
}
if (tp_add(tp, 1 + sizeof(uint32_t)) == NULL) {
goto oom_cant_encode_body;
}

ngx_memset(&unparsed_body, 0, sizeof(ngx_buf_t));
ngx_memset(&unparsed_body, 0, sizeof(ngx_buf_t));

unparsed_body.pos = ngx_pnalloc(r->pool,
sizeof(u_char) * r->headers_in.content_length_n + 1);
if (unparsed_body.pos == NULL) {
return NGX_ERROR;
}
unparsed_body.last = unparsed_body.pos;
unparsed_body.start = unparsed_body.pos;
unparsed_body.end = unparsed_body.pos +
r->headers_in.content_length_n + 1;

for (body = r->upstream->request_bufs; body; body = body->next) {
unparsed_body.pos = ngx_pnalloc(r->pool,
sizeof(u_char) * r->headers_in.content_length_n + 1);
if (unparsed_body.pos == NULL) {
return NGX_ERROR;
}
unparsed_body.last = unparsed_body.pos;
unparsed_body.start = unparsed_body.pos;
unparsed_body.end = unparsed_body.pos +
r->headers_in.content_length_n + 1;

b = body->buf;
for (body = r->upstream->request_bufs; body; body = body->next) {

if (b->in_file) {
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
"in-file buffer found. aborted. "
"consider increasing your 'client_body_buffer_size' "
"setting");
return NGX_ERROR;
}
b = body->buf;

unparsed_body.last = ngx_copy(unparsed_body.last,
b->pos, b->last - b->pos);
if (b->in_file) {
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
"in-file buffer found. aborted. "
"consider increasing your 'client_body_buffer_size' "
"setting");
return NGX_ERROR;
}

/** Actually this is an array not a map, I used this variable
* since it's avaliable in this scope
*/
map_items = 0;
unparsed_body.last = ngx_copy(unparsed_body.last,
b->pos, b->last - b->pos);
}

if (ngx_http_tnt_encode_urlencoded_body(r, tlcf, tp,
&unparsed_body, &map_items) != NGX_OK)
{
goto oom_cant_encode_body;
}
/** Actually this is an array not a map, I used this variable
* since it's avaliable in this scope
*/
map_items = 0;

*(map_place++) = 0xdd;
*(uint32_t *) map_place = mp_bswap_u32(map_items);
if (ngx_http_tnt_encode_urlencoded_body(r, tlcf, tp,
&unparsed_body, &map_items) != NGX_OK)
{
goto oom_cant_encode_body;
}

*(map_place++) = 0xdd;
*(uint32_t *) map_place = mp_bswap_u32(map_items);
}

/** Unknown body type - encode as mp string
*/
if ((tlcf->pass_http_request & NGX_TNT_CONF_PASS_BODY) &&
r->headers_in.content_length_n > 0 &&
r->upstream->request_bufs)
{
++root_items;

if (tp_encode_str(tp, "body", sizeof("body") - 1) == NULL) {
goto oom_cant_encode_body;
}
/** Unknown body type - encode as mp string
*/
else {

int sz = mp_sizeof_str(r->headers_in.content_length_n);
if (tp_ensure(tp, sz) == -1) {
goto oom_cant_encode_body;
}

p = mp_encode_strl(tp->p, r->headers_in.content_length_n);
int sz = mp_sizeof_str(r->headers_in.content_length_n);
if (tp_ensure(tp, sz) == -1) {
goto oom_cant_encode_body;
}

for (body = r->upstream->request_bufs; body; body = body->next) {
p = mp_encode_strl(tp->p, r->headers_in.content_length_n);

b = body->buf;
for (body = r->upstream->request_bufs; body; body = body->next) {

if (b->in_file) {
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
"in-file buffer found. aborted. "
"consider increasing your 'client_body_buffer_size' "
"setting");
return NGX_ERROR;
}
b = body->buf;

p = (char *) ngx_copy(p, b->pos, b->last - b->pos);
if (b->in_file) {
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
"in-file buffer found. aborted. "
"consider increasing your 'client_body_buffer_size' "
"setting");
return NGX_ERROR;
}

if (tp_add(tp, sz) == NULL) {
goto oom_cant_encode_body;
}
p = (char *) ngx_copy(p, b->pos, b->last - b->pos);
}

if (tp_add(tp, sz) == NULL) {
goto oom_cant_encode_body;
}
}

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.7.1"
#define NGX_HTTP_TNT_MODULE_VERSION_STRING "v2.7.2"

#endif