Skip to content

Commit 8a90974

Browse files
committed
Added PUT support
Signed-off-by: Nicholas Nezis <[email protected]>
1 parent 386e373 commit 8a90974

File tree

3 files changed

+37
-12
lines changed

3 files changed

+37
-12
lines changed

plugins/out_http/http.c

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,10 @@ static void append_headers(struct flb_http_client *c,
109109
}
110110
}
111111

112-
static int http_post(struct flb_out_http *ctx,
113-
const void *body, size_t body_len,
114-
const char *tag, int tag_len,
115-
char **headers)
112+
static int http_request(struct flb_out_http *ctx,
113+
const void *body, size_t body_len,
114+
const char *tag, int tag_len,
115+
char **headers)
116116
{
117117
int ret = 0;
118118
int out_ret = FLB_OK;
@@ -173,7 +173,7 @@ static int http_post(struct flb_out_http *ctx,
173173

174174

175175
/* Create HTTP client context */
176-
c = flb_http_client(u_conn, FLB_HTTP_POST, ctx->uri,
176+
c = flb_http_client(u_conn, ctx->http_method, ctx->uri,
177177
payload_buf, payload_size,
178178
ctx->host, ctx->port,
179179
ctx->proxy, 0);
@@ -598,8 +598,8 @@ static int post_all_requests(struct flb_out_http *ctx,
598598
}
599599

600600
if (body_found && headers_found) {
601-
flb_plg_trace(ctx->ins, "posting record %zu", record_count++);
602-
ret = http_post(ctx, body, body_size, event_chunk->tag,
601+
flb_plg_trace(ctx->ins, "sending record %zu", record_count++);
602+
ret = http_request(ctx, body, body_size, event_chunk->tag,
603603
flb_sds_len(event_chunk->tag), headers);
604604
}
605605
else {
@@ -649,15 +649,15 @@ static void cb_http_flush(struct flb_event_chunk *event_chunk,
649649
(ctx->out_format == FLB_PACK_JSON_FORMAT_STREAM) ||
650650
(ctx->out_format == FLB_PACK_JSON_FORMAT_LINES) ||
651651
(ctx->out_format == FLB_HTTP_OUT_GELF)) {
652-
ret = http_post(ctx, out_body, out_size,
653-
event_chunk->tag, flb_sds_len(event_chunk->tag), NULL);
652+
ret = http_request(ctx, out_body, out_size,
653+
event_chunk->tag, flb_sds_len(event_chunk->tag), NULL);
654654
flb_sds_destroy(out_body);
655655
}
656656
else {
657657
/* msgpack */
658-
ret = http_post(ctx,
659-
event_chunk->data, event_chunk->size,
660-
event_chunk->tag, flb_sds_len(event_chunk->tag), NULL);
658+
ret = http_request(ctx,
659+
event_chunk->data, event_chunk->size,
660+
event_chunk->tag, flb_sds_len(event_chunk->tag), NULL);
661661
}
662662
}
663663

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

763768
/* Gelf Properties */
764769
{

plugins/out_http/http.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ struct flb_out_http {
6767
char *host;
6868
int port;
6969

70+
/* HTTP method */
71+
int http_method;
72+
7073
/* GELF fields */
7174
struct flb_gelf_fields gelf_fields;
7275

plugins/out_http/http_conf.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,23 @@ struct flb_out_http *flb_http_conf_create(struct flb_output_instance *ins,
272272
}
273273
}
274274

275+
/* HTTP method */
276+
ctx->http_method = FLB_HTTP_POST;
277+
tmp = flb_output_get_property("http_method", ins);
278+
if (tmp) {
279+
if (strcasecmp(tmp, "POST") == 0) {
280+
ctx->http_method = FLB_HTTP_POST;
281+
}
282+
else if (strcasecmp(tmp, "PUT") == 0) {
283+
ctx->http_method = FLB_HTTP_PUT;
284+
}
285+
else {
286+
flb_plg_error(ctx->ins, "invalid http_method option '%s'. Supported methods are POST and PUT", tmp);
287+
flb_free(ctx);
288+
return NULL;
289+
}
290+
}
291+
275292
ctx->u = upstream;
276293
ctx->uri = uri;
277294
ctx->host = ins->host.name;

0 commit comments

Comments
 (0)