Skip to content

Conversation

@bas0N
Copy link
Contributor

@bas0N bas0N commented Nov 18, 2025

Set charset=utf-8 in Content-Type header to ensure proper display of Cyrillic and other Unicode characters in browsers.

Fixes #13952

Proposed Changes

This PR fixes incorrect encoding display for Cyrillic and other Unicode characters when viewing trace log files through the RabbitMQ management UI. The issue was that browsers were misinterpreting UTF-8 encoded content as Latin-1 when no charset was specified in the Content-Type header.

Why this change:

  • Trace files are written in UTF-8 by rabbit_tracing_consumer (using io_lib:format and rabbit_json:encode)
  • Without an explicit charset parameter, browsers default to Latin-1/ISO-8859-1, causing Cyrillic characters to display as garbled text (e.g., Привет мирПривет мир)
  • Adding charset=utf-8 to the Content-Type header ensures browsers correctly interpret the file content

Solution chosen:
The original issue suggested a client-side JavaScript solution, but we implemented a server-side fix instead because:

  • Server-side solution provides a proper URL in the browser (the JS solution resulted in about:blank)
  • More reliable and standard approach (charset should be specified in HTTP headers)
  • Simpler and cleaner - no client-side workarounds needed
  • Follows HTTP best practices (RFC 7231)

Types of Changes

What types of changes does your code introduce to this project?
Put an x in the boxes that apply

  • Bug fix (non-breaking change which fixes issue rabbitmq_tracing should open trace files using UTF-8 for encoding #13952)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause an observable behavior change in existing systems)
  • Documentation improvements (corrections, new content, etc)
  • Cosmetic change (whitespace, formatting, etc)
  • Build system and/or CI

Checklist

Put an x in the boxes that apply.
You can also fill these out after creating the PR.
This is simply a reminder of what we are going to look for before merging your code.

  • Mandatory: I (or my employer/client) have have signed the CA (see https://github.com/rabbitmq/cla)
  • I have read the CONTRIBUTING.md document
  • I have added tests that prove my fix is effective or that my feature works
  • All tests pass locally with my changes
  • If relevant, I have added necessary documentation to https://github.com/rabbitmq/rabbitmq-website
  • If relevant, I have added this change to the first version(s) in release-notes that I expect to introduce it

Further Comments

Changes made:

  • Modified deps/rabbitmq_tracing/src/rabbit_tracing_wm_file.erl to set Content-Type: text/plain; charset=utf-8 header in serve/2
  • Added test trace_file_content_type_test in deps/rabbitmq_tracing/test/rabbit_tracing_SUITE.erl to verify the Content-Type header includes charset

Why this is safe:

  • Content negotiation remains unchanged (still accepts text/plain)
  • Charset is optional metadata per RFC 7231 - adding it doesn't break compatibility
  • Trace files are consistently written as UTF-8 by the plugin
  • Similar pattern exists elsewhere in codebase (e.g., rabbit_mgmt_oauth_bootstrap.erl sets text/javascript; charset=utf-8)

Testing:

  • Added test case that verifies Content-Type header contains both text/plain and charset=utf-8
  • Manually tested with Cyrillic characters - displays correctly in browsers
  • Existing tests continue to pass

Before the fix:
Before the fix

After the fix:
After the fix

Set charset=utf-8 in Content-Type header to ensure proper display of Cyrillic and other Unicode characters in browsers.

Fixes rabbitmq#13952
@michaelklishin michaelklishin changed the title Fix UTF-8 encoding for trace file downloads rabbitmq_tracing: explicitly specify UTF-8 encoding for served trace files Nov 18, 2025
- Replace timer:sleep(100) with await_condition/1 to wait for trace files
  instead of using fixed delays, making tests more reliable
- Remove explicit close_channel calls for managed CT helper channels
- Add http_get_headers/5 helper function following the same pattern
  as http_get/5 and http_get_raw/5, replacing direct req/4 calls
- Use helper function to validate HTTP status codes and return headers
  consistently with the module's existing helper pattern
Replace manual header setting with charsets_provided/2 callback to
let Cowboy handle charset negotiation automatically.
@michaelklishin michaelklishin merged commit 74505cf into rabbitmq:main Nov 18, 2025
574 of 575 checks passed
michaelklishin added a commit that referenced this pull request Nov 19, 2025
rabbitmq_tracing: explicitly specify UTF-8 encoding for served trace files (backport #14966)
@michaelklishin michaelklishin added this to the 4.2.2 milestone Nov 19, 2025
@michaelklishin
Copy link
Collaborator

Thank you for contributing, @bas0N.

michaelklishin added a commit that referenced this pull request Nov 19, 2025
rabbitmq_tracing: explicitly specify UTF-8 encoding for served trace files (backport #14966) (backport #14970)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

rabbitmq_tracing should open trace files using UTF-8 for encoding

3 participants