Skip to content

Commit 19a0c03

Browse files
nokute78edsiper
authored andcommitted
in_http: support 'successful_response_code' (#3644)
The property 'successful_response_code' allows to modify response code. Currently, we can set 200, 201(Default) and 204. Note: Fluentd supports 200 and 204 with 'use_204_response' Signed-off-by: Takahiro Yamashita <[email protected]>
1 parent e0c4b4d commit 19a0c03

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

plugins/in_http/http.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,14 @@ static int in_http_init(struct flb_input_instance *ins,
9191
return -1;
9292
}
9393

94+
if (ctx->successful_response_code != 200 &&
95+
ctx->successful_response_code != 201 &&
96+
ctx->successful_response_code != 204) {
97+
flb_plg_error(ctx->ins, "%d is not supported response code. Use default 201",
98+
ctx->successful_response_code);
99+
ctx->successful_response_code = 201;
100+
}
101+
94102
/* Set the socket non-blocking */
95103
flb_net_socket_nonblocking(ctx->server_fd);
96104

@@ -140,6 +148,12 @@ static struct flb_config_map config_map[] = {
140148
0, FLB_TRUE, offsetof(struct flb_http, tag_key),
141149
""
142150
},
151+
{
152+
FLB_CONFIG_MAP_INT, "successful_response_code", "201",
153+
0, FLB_TRUE, offsetof(struct flb_http, successful_response_code),
154+
"Set successful response code. 200, 201 and 204 are supported."
155+
},
156+
143157

144158
/* EOF */
145159
{0}

plugins/in_http/http.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
struct flb_http {
3434
int server_fd;
35+
int successful_response_code;
3536
flb_sds_t listen;
3637
flb_sds_t tcp_port;
3738
const char *tag_key;

plugins/in_http/http_prot.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,20 @@ static int send_response(struct http_conn *conn, int http_status, char *message)
5555
"Content-Length: 0\r\n\r\n",
5656
FLB_VERSION_STR);
5757
}
58+
else if (http_status == 200) {
59+
flb_sds_printf(&out,
60+
"HTTP/1.1 200 OK\r\n"
61+
"Server: Fluent Bit v%s\r\n"
62+
"Content-Length: 0\r\n\r\n",
63+
FLB_VERSION_STR);
64+
}
65+
else if (http_status == 204) {
66+
flb_sds_printf(&out,
67+
"HTTP/1.1 204 No Content\r\n"
68+
"Server: Fluent Bit v%s\r\n"
69+
"Content-Length: 0\r\n\r\n",
70+
FLB_VERSION_STR);
71+
}
5872
else if (http_status == 400) {
5973
flb_sds_printf(&out,
6074
"HTTP/1.1 400 Forbidden\r\n"
@@ -428,6 +442,6 @@ int http_prot_handle(struct flb_http *ctx, struct http_conn *conn,
428442

429443
ret = process_payload(ctx, conn, tag, session, request);
430444
flb_sds_destroy(tag);
431-
send_response(conn, 201, NULL);
445+
send_response(conn, ctx->successful_response_code, NULL);
432446
return ret;
433447
}

0 commit comments

Comments
 (0)