Browse Source

#97 - done

tags/v2.5-r2
V. Soshnikov 2 years ago
parent
commit
884ba3ebaa

+ 1
- 1
README.md View File

@@ -809,7 +809,7 @@ When this option is on:
[Back to content](#content)
tnt_multireturn_skip_count - DEPRECATED in 2.4.0+
tnt_multireturn_skip_count - DEPRECATED in 2.4.0+, RETURNED IN 2.4.6-rc3+
-------------------------------------------------
**syntax:** *tnt_multireturn_skip_count [0|1|2]*

+ 8
- 0
src/ngx_http_tnt_handlers.h View File

@@ -119,6 +119,14 @@ typedef struct {
*/
ngx_uint_t pure_result;

/** Tarantool returns array of array as the result set,
* this option will help avoid "array of array" behavior.
* For instance.
* If this option is set to 2, then the result will: result:{}.
* If this option is set to 0, then the result will: result:[[{}]].
*/
ngx_uint_t multireturn_skip_count;

ngx_array_t *headers;

} ngx_http_tnt_loc_conf_t;

+ 14
- 1
src/ngx_http_tnt_module.c View File

@@ -209,6 +209,14 @@ static ngx_command_t ngx_http_tnt_commands[] = {
offsetof(ngx_http_tnt_loc_conf_t, pure_result),
&ngx_http_tnt_pass_http_request_masks },

{ ngx_string("tnt_multireturn_skip_count"),
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
ngx_conf_set_size_slot,
NGX_HTTP_LOC_CONF_OFFSET,
offsetof(ngx_http_tnt_loc_conf_t, multireturn_skip_count),
NULL },

{ ngx_string("tnt_http_methods"),
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
ngx_conf_set_bitmask_slot,
@@ -379,6 +387,7 @@ ngx_http_tnt_create_loc_conf(ngx_conf_t *cf)
conf->upstream.buffer_size =
conf->in_multiplier =
conf->out_multiplier =
conf->multireturn_skip_count =
conf->pass_http_request_buffer_size = NGX_CONF_UNSET_SIZE;

/*
@@ -467,6 +476,9 @@ ngx_http_tnt_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
ngx_conf_merge_bitmask_value(conf->pure_result, prev->pure_result,
NGX_TNT_CONF_OFF);

ngx_conf_merge_size_value(conf->multireturn_skip_count,
prev->multireturn_skip_count, 0);

if (conf->headers == NULL) {
conf->headers = prev->headers;
}
@@ -714,7 +726,8 @@ ngx_http_tnt_send_reply(ngx_http_request_t *r,
return NGX_ERROR;
}

tp_reply_to_json_set_options(&tc, tlcf->pure_result == NGX_TNT_CONF_ON);
tp_reply_to_json_set_options(&tc, tlcf->pure_result == NGX_TNT_CONF_ON,
tlcf->multireturn_skip_count);

rc = tp_transcode(&tc, (char *)ctx->tp_cache->start,
ctx->tp_cache->end - ctx->tp_cache->start);

+ 1
- 1
src/ngx_http_tnt_version.h View File

@@ -33,6 +33,6 @@
#ifndef NGX_HTTP_TNT_VERSION_H
#define NGX_HTTP_TNT_VERSION_H 1

#define NGX_HTTP_TNT_MODULE_VERSION_STRING "v2.4.6-rc2"
#define NGX_HTTP_TNT_MODULE_VERSION_STRING "v2.5-rc2"

#endif

+ 29
- 13
src/tp_transcode.c View File

@@ -823,6 +823,9 @@ typedef struct tp2json {
*/
bool pure_result;

size_t multireturn_skip_count;
size_t multireturn_skiped;

} tp2json_t;

static inline int
@@ -957,20 +960,29 @@ tp2json_transcode_internal(tp2json_t *ctx, const char **beg, const char *end)
{
const uint32_t size = mp_decode_array(beg);

if (unlikely(len < size + 2/*,[]*/))
OOM_TP2JSON;
if (ctx->multireturn_skiped > 0) {

APPEND_CH('[');
uint32_t i = 0;
for (i = 0; i < size; i++) {
if (i)
APPEND_CH(',');
rc = tp2json_transcode_internal(ctx, beg, end);
if (rc != TP_TRANSCODE_OK)
return rc;
}
APPEND_CH(']');
--ctx->multireturn_skiped;
rc = tp2json_transcode_internal(ctx, beg, end);
if (rc != TP_TRANSCODE_OK)
return rc;

} else {

if (unlikely(len < size + 2 /*,[]*/))
OOM_TP2JSON;

APPEND_CH('[');
uint32_t i = 0;
for (i = 0; i < size; i++) {
if (i)
APPEND_CH(',');
rc = tp2json_transcode_internal(ctx, beg, end);
if (rc != TP_TRANSCODE_OK)
return rc;
}
APPEND_CH(']');
}
break;
}
case MP_MAP:
@@ -1050,6 +1062,7 @@ tp_reply2json_transcode(void *ctx_, const char *in, size_t in_size)
}

ctx->first_entry = false;
ctx->multireturn_skiped = ctx->multireturn_skip_count;
}

if (ctx->r.error) {
@@ -1275,12 +1288,15 @@ tp_transcode_bind_data(tp_transcode_t *t,
}

void
tp_reply_to_json_set_options(tp_transcode_t *t, bool pure_result)
tp_reply_to_json_set_options(tp_transcode_t *t,
bool pure_result,
size_t multireturn_skip_count)
{
assert(t);
assert(t->codec.ctx);
tp2json_t *ctx = t->codec.ctx;
ctx->pure_result = pure_result;
ctx->multireturn_skip_count = multireturn_skip_count;
}

bool

+ 2
- 1
src/tp_transcode.h View File

@@ -177,7 +177,8 @@ void tp_transcode_bind_data(tp_transcode_t *t,
/**
*/
void
tp_reply_to_json_set_options(tp_transcode_t *t, bool pure_result);
tp_reply_to_json_set_options(tp_transcode_t *t, bool pure_result,
size_t multireturn_skip_count);

/**
* WARNING! tp_dump() is for debug!

+ 12
- 0
t/ngx_confs/tnt_server_test.conf View File

@@ -294,5 +294,17 @@ http {
tnt_pass tnt;
}

location /skip_count_1 {
tnt_method echo_2;
tnt_multireturn_skip_count 1;
tnt_pass tnt;
}

location /skip_count_2 {
tnt_method echo_2;
tnt_multireturn_skip_count 2;
tnt_pass tnt;
}

}
}

+ 18
- 0
t/v25_features.py View File

@@ -88,6 +88,24 @@ assert rc == 200, "rc != 200"
assert len(out['result'][0]['body']) == 4, 'expected 4'
for k in out['result'][0]['body']:
assert k['a'] == 'b', 'not expected'
print ('[+] OK')


print ('[+] Post - skip_count_1')
preset_method_location = BASE_URL + '/skip_count_1'
rc, out = post(preset_method_location, {'params': [{"arg1": 1}], 'id': 1},
default_headers)
assert rc == 200, "rc != 200"
assert len(out['result']) == 1, 'result should be an array with 2 elems'
assert out['result'][0]['arg1'] == 1, 'arg1 != 1'
print ('[+] OK')


print ('[+] Post - skip_count_2')
preset_method_location = BASE_URL + '/skip_count_2'
rc, out = post(preset_method_location, {'params': [{"arg1": 1}], 'id': 1},
default_headers)
assert rc == 200, "rc != 200"
assert isinstance(out['result'], dict), 'not {}'
assert out['result']['arg1'] == 1, 'arg1 != 1'
print ('[+] OK')

Loading…
Cancel
Save