Skip to content

Commit e7d0484

Browse files
committed
Added PUT support
1 parent 60db310 commit e7d0484

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);
@@ -596,8 +596,8 @@ static int post_all_requests(struct flb_out_http *ctx,
596596
}
597597

598598
if (body_found && headers_found) {
599-
flb_plg_trace(ctx->ins, "posting record %zu", record_count++);
600-
ret = http_post(ctx, body, body_size, event_chunk->tag,
599+
flb_plg_trace(ctx->ins, "sending record %zu", record_count++);
600+
ret = http_request(ctx, body, body_size, event_chunk->tag,
601601
flb_sds_len(event_chunk->tag), headers);
602602
}
603603
else {
@@ -647,15 +647,15 @@ static void cb_http_flush(struct flb_event_chunk *event_chunk,
647647
(ctx->out_format == FLB_PACK_JSON_FORMAT_STREAM) ||
648648
(ctx->out_format == FLB_PACK_JSON_FORMAT_LINES) ||
649649
(ctx->out_format == FLB_HTTP_OUT_GELF)) {
650-
ret = http_post(ctx, out_body, out_size,
651-
event_chunk->tag, flb_sds_len(event_chunk->tag), NULL);
650+
ret = http_request(ctx, out_body, out_size,
651+
event_chunk->tag, flb_sds_len(event_chunk->tag), NULL);
652652
flb_sds_destroy(out_body);
653653
}
654654
else {
655655
/* msgpack */
656-
ret = http_post(ctx,
657-
event_chunk->data, event_chunk->size,
658-
event_chunk->tag, flb_sds_len(event_chunk->tag), NULL);
656+
ret = http_request(ctx,
657+
event_chunk->data, event_chunk->size,
658+
event_chunk->tag, flb_sds_len(event_chunk->tag), NULL);
659659
}
660660
}
661661

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

761766
/* Gelf Properties */
762767
{

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)