-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
in_http: Content-Type rejected for application/json when encoding value is present. #9023
Conversation
It would probably be good to add some simple tests as well to prevent any future regressions? |
Can you update your commit messages to follow the contribution guide format? |
@patrick-stephens I wasn't able to get my local environment setup to correctly produce tests but based on the docs I took a stab at it: e66f29d |
I managed to mostly get the test running with this patch: diff --git a/tests/runtime/in_http.c b/tests/runtime/in_http.c
index 5bb440265..4fc4e342f 100644
--- a/tests/runtime/in_http.c
+++ b/tests/runtime/in_http.c
@@ -351,8 +351,9 @@ void flb_test_http_successful_response_code(char *response_code)
test_ctx_destroy(ctx);
}
-void flb_test_http_json_charset_header_successful_response_code(char *response_code)
+void flb_test_http_json_charset_header()
{
+ char *response_code = "200";
struct flb_lib_out_cb cb_data;
struct test_ctx *ctx;
struct flb_http_client *c;
@@ -360,7 +361,7 @@ void flb_test_http_json_charset_header_successful_response_code(char *response_c
int num;
size_t b_sent;
- char *buf = "{\"test\":\"msg\"}";
+ char *buf = "[{\"test\":\"msg\"}]";
clear_output_num();
@@ -391,6 +392,8 @@ void flb_test_http_json_charset_header_successful_response_code(char *response_c
ctx->httpc = http_client_ctx_create();
TEST_CHECK(ctx->httpc != NULL);
+ flb_time_msleep(1500);
+
c = flb_http_client(ctx->httpc->u_conn, FLB_HTTP_POST, "/", buf, strlen(buf),
"127.0.0.1", 9880, NULL, 0);
ret = flb_http_add_header(c, FLB_HTTP_HEADER_CONTENT_TYPE, strlen(FLB_HTTP_HEADER_CONTENT_TYPE),
@@ -662,6 +665,7 @@ TEST_LIST = {
{"successful_response_code_204", flb_test_http_successful_response_code_204},
{"failure_response_code_400_bad_json", flb_test_http_failure_400_bad_json},
{"failure_response_code_400_bad_disk_write", flb_test_http_failure_400_bad_disk_write},
+ {"json_charset_header", flb_test_http_json_charset_header},
{"tag_key", flb_test_http_tag_key},
{NULL, NULL}
}; The test runs but fails since the http service is responding with 400. The code works when I test it directly via the command line so there must be something the test code is not doing correctly. |
@pwhelan Is it possible the test server is just rejecting the request based on the content type header? Is it checking length to ensure it 16 characters long? Encoding should default to utf-8 so I would assume test http server would not perform any additional validation. |
Note the change is failing to compile on the older compiler for CentOS 7 which is a hard block on merging. |
@patrick-stephens @pwhelan any follow-up from me still needed on this PR? |
Should this be moved to Milestone |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Awesome work getting the tests working.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please revert all file changes caused by line encoding switches?
That would be even more important than the code change I requested because this PR should only touch the code file you changed and the test file where you added your test in order to be merged.
Regards.
@@ -523,7 +523,7 @@ static int process_payload(struct flb_http *ctx, struct http_conn *conn, | |||
return -1; | |||
} | |||
|
|||
if (header->val.len == 16 && | |||
if (header->val.len >= 16 && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to RFC 2616, media types can have parameters which should be separated from the main type and subtype with a colon (and I think optionally a space) which means, in the case of a value longer than 16 characters you would have to verify that the seventeenth character is either a space a colon in order to avoid matching values like "application/json_but_with_some_twist_that_we_do_not_want_to_match".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@leonardo-albertovich Did you mean semi-colon? ;
?
There are things that need to be fixed before this can be merged.
Hi @metalfork, do you think you'll be able to make those changes? |
… valid application/json and not some custom unexpected media type. Signed-off-by: metalfork <[email protected]>
|
The failing test happened due to github, as far as I can tell. There are still changes in the files outside of the The easiest way forward might be to clone a fresh repository, add the changed files on top, commit again and push with |
Updated
application/json
Content-Type
header detect to allow detectingapplication/json
when length is longer than 16 character because of addition encoding in the header value, akaContent-type: application/json; charset=utf-8
Enter
[N/A]
in the box, if an item is not applicable to your change.Testing
Before we can approve your change; please submit the following in a comment:
If this is a change to packaging of containers or native binaries then please confirm it works for all targets.
ok-package-test
label to test for all targets (requires maintainer to do).Documentation
Backporting
Fluent Bit is licensed under Apache 2.0, by submitting this pull request I understand that this code will be released under the terms of that license.