Skip to content
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

How to get rid of charset from Content-Type header when Posting request to logstash using http sink #43

Closed
msdotnet opened this issue Jan 19, 2018 · 6 comments

Comments

@msdotnet
Copy link

Step 1: Describe your environment

  • Windows Server 2012

Step 2: Describe the problem

When sending Post request using http sink to logstash, data is being saved as string in the message field not as object. This is happening because of charset presence in the Content-Type header

Observed results

By default when Serilog is sending POST request to Logstash, it's adding "Content-type: application/json; charset=utf-8” to the request header. How can I just send just "Content-type: application/json” without charset

Expected results

Need to just get rid of charset from Content-Type header value when Posting request to logstash

@FantasticFiasco
Copy link
Owner

data is being saved as string in the message field not as object.

I don't follow you here. The message template and the rendered message is of type string, even in the serialized JSON. The JSON will also have a property called Properties holding the structured data. This is by design and has nothing to do with UTF-8 encoding of the request content.

Do you have any problems on the receiving side with UTF-8 as content encoding?

For a quick fix, you can always provide your own implementation of IHttpClient when creating the sink, there is already support for that.

@msdotnet
Copy link
Author

Thanks for your valuable reply. Setting codec=> json in the logstash config file has resolved the issue.

@FantasticFiasco
Copy link
Owner

Now I understand what you meant, sorry that my answer wasn't more precise.

For a detailed example of sending log event to Elastic Stack, you can always take a look at my other repo called serilog-sinks-http-elastic-stack. It has the configuration you mentioned, and is why I apologize I didn't get that through to you almost two weeks ago.

@skasliwal-Liv
Copy link

@FantasticFiasco - I am facing the same issue while sending the data to Fluentbit . It is always adding the Charset in the content-type header and thats why its failing to send logs to Fluentbit Http input. is there any way to get rid of charset when sending the post request ?

@FantasticFiasco
Copy link
Owner

I think the runtime appends the charset to the header, because the code in this sink is setting the header to application/json (see source).

Since the sink isn't adding the charset, I'm at a loss on how to remove it.

@metalfork
Copy link

metalfork commented Jun 27, 2024

@FantasticFiasco the charset is being added via HttpHeaders. Opened an issue with fluent-bit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants