Coverage Report

Created: 2026-03-09 07:04

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/fluent-bit/plugins/out_td/td_http.c
Line
Count
Source
1
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3
/*  Fluent Bit
4
 *  ==========
5
 *  Copyright (C) 2015-2026 The Fluent Bit Authors
6
 *
7
 *  Licensed under the Apache License, Version 2.0 (the "License");
8
 *  you may not use this file except in compliance with the License.
9
 *  You may obtain a copy of the License at
10
 *
11
 *      http://www.apache.org/licenses/LICENSE-2.0
12
 *
13
 *  Unless required by applicable law or agreed to in writing, software
14
 *  distributed under the License is distributed on an "AS IS" BASIS,
15
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
 *  See the License for the specific language governing permissions and
17
 *  limitations under the License.
18
 */
19
20
#include <fluent-bit/flb_output_plugin.h>
21
#include <fluent-bit/flb_gzip.h>
22
#include <fluent-bit/flb_config.h>
23
#include <fluent-bit/flb_http_client.h>
24
25
#include "td_config.h"
26
27
#include <stdio.h>
28
#include <stdlib.h>
29
#include <string.h>
30
31
32
#define TD_HTTP_HEADER_SIZE  512
33
34
struct flb_http_client *td_http_client(struct flb_connection *u_conn,
35
                                       void *data, size_t len,
36
                                       char **body,
37
                                       struct flb_td *ctx,
38
                                       struct flb_config *config)
39
0
{
40
0
    int ret;
41
0
    int pos = 0;
42
0
    int api_len;
43
0
    size_t gz_size;
44
0
    void *gz_data;
45
0
    char *tmp;
46
0
    struct flb_http_client *c;
47
48
    /* Compress data */
49
0
    ret = flb_gzip_compress(data, len, &gz_data, &gz_size);
50
0
    if (ret == -1) {
51
0
        flb_plg_error(ctx->ins, "error compressing data");
52
0
        return NULL;
53
0
    }
54
55
    /* Compose URI */
56
0
    tmp = flb_malloc(512);
57
0
    if (!tmp) {
58
0
        flb_free(gz_data);
59
0
        return NULL;
60
0
    }
61
0
    snprintf(tmp, 256,
62
0
             "/v3/table/import/%s/%s/msgpack.gz",
63
0
             ctx->db_name, ctx->db_table);
64
65
    /* Create client */
66
0
    c = flb_http_client(u_conn, FLB_HTTP_PUT, tmp,
67
0
                        gz_data, gz_size, NULL, 0, NULL, 0);
68
0
    if (!c) {
69
0
        flb_free(tmp);
70
0
        flb_free(gz_data);
71
0
        return NULL;
72
0
    }
73
74
    /* Add custom headers */
75
0
    tmp[pos++] = 'T';
76
0
    tmp[pos++] = 'D';
77
0
    tmp[pos++] = '1';
78
0
    tmp[pos++] = ' ';
79
80
0
    api_len = strlen(ctx->api);
81
0
    memcpy(tmp + pos, ctx->api, api_len);
82
0
    pos += api_len;
83
84
0
    flb_http_add_header(c,
85
0
                        "Authorization", 13,
86
0
                        tmp, pos);
87
0
    flb_http_add_header(c,
88
0
                        "Content-Type", 12,
89
0
                        "application/gzip", 16);
90
0
    flb_free(tmp);
91
0
    *body = gz_data;
92
93
0
    return c;
94
0
}