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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 22 additions & 15 deletions plugins/out_http/http.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,10 @@ static void append_headers(struct flb_http_client *c,
}
}

static int http_post(struct flb_out_http *ctx,
const void *body, size_t body_len,
const char *tag, int tag_len,
char **headers)
static int http_request(struct flb_out_http *ctx,
const void *body, size_t body_len,
const char *tag, int tag_len,
char **headers)
{
int ret = 0;
int out_ret = FLB_OK;
Expand Down Expand Up @@ -173,7 +173,7 @@ static int http_post(struct flb_out_http *ctx,


/* Create HTTP client context */
c = flb_http_client(u_conn, FLB_HTTP_POST, ctx->uri,
c = flb_http_client(u_conn, ctx->http_method, ctx->uri,
payload_buf, payload_size,
ctx->host, ctx->port,
ctx->proxy, 0);
Expand Down Expand Up @@ -529,7 +529,7 @@ static char **extract_headers(msgpack_object *obj) {
return NULL;
}

static int post_all_requests(struct flb_out_http *ctx,
static int send_all_requests(struct flb_out_http *ctx,
const char *data, size_t size,
flb_sds_t body_key,
flb_sds_t headers_key,
Expand Down Expand Up @@ -598,8 +598,10 @@ static int post_all_requests(struct flb_out_http *ctx,
}

if (body_found && headers_found) {
flb_plg_trace(ctx->ins, "posting record %zu", record_count++);
ret = http_post(ctx, body, body_size, event_chunk->tag,
flb_plg_trace(ctx->ins, "sending record %zu via %s",
record_count++,
ctx->http_method == FLB_HTTP_POST ? "POST" : "PUT");
ret = http_request(ctx, body, body_size, event_chunk->tag,
flb_sds_len(event_chunk->tag), headers);
}
else {
Expand Down Expand Up @@ -631,11 +633,11 @@ static void cb_http_flush(struct flb_event_chunk *event_chunk,
(void) i_ins;

if (ctx->body_key) {
ret = post_all_requests(ctx, event_chunk->data, event_chunk->size,
ret = send_all_requests(ctx, event_chunk->data, event_chunk->size,
ctx->body_key, ctx->headers_key, event_chunk);
if (ret < 0) {
flb_plg_error(ctx->ins,
"failed to post requests body key \"%s\"", ctx->body_key);
"failed to send requests using body key \"%s\"", ctx->body_key);
}
}
else {
Expand All @@ -649,15 +651,15 @@ static void cb_http_flush(struct flb_event_chunk *event_chunk,
(ctx->out_format == FLB_PACK_JSON_FORMAT_STREAM) ||
(ctx->out_format == FLB_PACK_JSON_FORMAT_LINES) ||
(ctx->out_format == FLB_HTTP_OUT_GELF)) {
ret = http_post(ctx, out_body, out_size,
event_chunk->tag, flb_sds_len(event_chunk->tag), NULL);
ret = http_request(ctx, out_body, out_size,
event_chunk->tag, flb_sds_len(event_chunk->tag), NULL);
flb_sds_destroy(out_body);
}
else {
/* msgpack */
ret = http_post(ctx,
event_chunk->data, event_chunk->size,
event_chunk->tag, flb_sds_len(event_chunk->tag), NULL);
ret = http_request(ctx,
event_chunk->data, event_chunk->size,
event_chunk->tag, flb_sds_len(event_chunk->tag), NULL);
}
}

Expand Down Expand Up @@ -759,6 +761,11 @@ static struct flb_config_map config_map[] = {
0, FLB_TRUE, offsetof(struct flb_out_http, uri),
"Specify an optional HTTP URI for the target web server, e.g: /something"
},
{
FLB_CONFIG_MAP_STR, "http_method", "POST",
0, FLB_FALSE, 0,
"Specify the HTTP method to use. Supported methods are POST and PUT"
},

/* Gelf Properties */
{
Expand Down
3 changes: 3 additions & 0 deletions plugins/out_http/http.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ struct flb_out_http {
char *host;
int port;

/* HTTP method */
int http_method;

/* GELF fields */
struct flb_gelf_fields gelf_fields;

Expand Down
18 changes: 18 additions & 0 deletions plugins/out_http/http_conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <fluent-bit/flb_pack.h>
#include <fluent-bit/flb_sds.h>
#include <fluent-bit/flb_kv.h>
#include <fluent-bit/flb_http_client.h>
#include <fluent-bit/flb_record_accessor.h>

#ifdef FLB_HAVE_SIGNV4
Expand Down Expand Up @@ -272,6 +273,23 @@ struct flb_out_http *flb_http_conf_create(struct flb_output_instance *ins,
}
}

/* HTTP method */
ctx->http_method = FLB_HTTP_POST;
tmp = flb_output_get_property("http_method", ins);
if (tmp) {
if (strcasecmp(tmp, "POST") == 0) {
ctx->http_method = FLB_HTTP_POST;
}
else if (strcasecmp(tmp, "PUT") == 0) {
ctx->http_method = FLB_HTTP_PUT;
}
else {
flb_plg_error(ctx->ins, "invalid http_method option '%s'. Supported methods are POST and PUT", tmp);
flb_free(ctx);
return NULL;
}
}

ctx->u = upstream;
ctx->uri = uri;
ctx->host = ins->host.name;
Expand Down
Loading