diff --git a/plugins/out_http/http.c b/plugins/out_http/http.c index 88b62673742..bf59fbe76d3 100644 --- a/plugins/out_http/http.c +++ b/plugins/out_http/http.c @@ -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; @@ -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); @@ -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, @@ -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 { @@ -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 { @@ -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); } } @@ -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 */ { diff --git a/plugins/out_http/http.h b/plugins/out_http/http.h index 4373f2c2e2a..2a0b3ca5c91 100644 --- a/plugins/out_http/http.h +++ b/plugins/out_http/http.h @@ -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; diff --git a/plugins/out_http/http_conf.c b/plugins/out_http/http_conf.c index 24f93ca94d8..a9aa2596cae 100644 --- a/plugins/out_http/http_conf.c +++ b/plugins/out_http/http_conf.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #ifdef FLB_HAVE_SIGNV4 @@ -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;