diff --git a/plugins/in_http/http_prot.c b/plugins/in_http/http_prot.c index 175fe4461e1..4e2aa6a761c 100644 --- a/plugins/in_http/http_prot.c +++ b/plugins/in_http/http_prot.c @@ -843,6 +843,11 @@ static int process_pack_ng(struct flb_http *ctx, flb_sds_t tag, char *buf, size_ { record = obj->via.array.ptr[i]; + tag_from_record = NULL; + if (ctx->tag_key) { + tag_from_record = tag_key(ctx, &record); + } + if (tag_from_record) { ret = process_pack_record(ctx, &tm, tag_from_record, &record); flb_sds_destroy(tag_from_record); diff --git a/tests/runtime/in_http.c b/tests/runtime/in_http.c index d4d88faadf8..66ddaea5230 100644 --- a/tests/runtime/in_http.c +++ b/tests/runtime/in_http.c @@ -588,7 +588,7 @@ void flb_test_http_failure_400_bad_disk_write() test_ctx_destroy(ctx); } -void flb_test_http_tag_key() +void test_http_tag_key(char *input) { struct flb_lib_out_cb cb_data; struct test_ctx *ctx; @@ -597,7 +597,7 @@ void flb_test_http_tag_key() int num; size_t b_sent; - char *buf = "{\"test\":\"msg\", \"tag\":\"new_tag\"}"; + char *buf = input; clear_output_num(); @@ -661,12 +661,23 @@ void flb_test_http_tag_key() test_ctx_destroy(ctx); } +void flb_test_http_tag_key_with_map_input() +{ + test_http_tag_key("{\"tag\":\"new_tag\",\"test\":\"msg\"}"); +} + +void flb_test_http_tag_key_with_array_input() +{ + test_http_tag_key("[{\"tag\":\"new_tag\",\"test\":\"msg\"}]"); +} + TEST_LIST = { {"http", flb_test_http}, {"successful_response_code_200", flb_test_http_successful_response_code_200}, {"successful_response_code_204", flb_test_http_successful_response_code_204}, {"failure_response_code_400_bad_json", flb_test_http_failure_400_bad_json}, {"failure_response_code_400_bad_disk_write", flb_test_http_failure_400_bad_disk_write}, - {"tag_key", flb_test_http_tag_key}, + {"tag_key_with_map_input", flb_test_http_tag_key_with_map_input}, + {"tag_key_with_array_input", flb_test_http_tag_key_with_array_input}, {NULL, NULL} };