Skip to content

Conversation

@mergify
Copy link

@mergify mergify bot commented Nov 19, 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.

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


This is an automatic backport of pull request #14966 done by [Mergify](https://mergify.com).
This is an automatic backport of pull request #14970 done by [Mergify](https://mergify.com).

bas0N and others added 5 commits November 19, 2025 04:01
Set charset=utf-8 in Content-Type header to ensure proper display of Cyrillic and other Unicode characters in browsers.

Fixes #13952

(cherry picked from commit 8795c5d)
(cherry picked from commit b85baea)
(cherry picked from commit be75522)

# Conflicts:
#	release-notes/4.3.0.md
(cherry picked from commit 767212d)
- 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

(cherry picked from commit b606cc0)
(cherry picked from commit a6c74ec)
Replace manual header setting with charsets_provided/2 callback to
let Cowboy handle charset negotiation automatically.

(cherry picked from commit c1cc495)
(cherry picked from commit 1fc11e9)
(cherry picked from commit f5a7454)
@michaelklishin michaelklishin added this to the 4.1.7 milestone Nov 19, 2025
@michaelklishin michaelklishin merged commit da27d18 into v4.1.x Nov 19, 2025
1084 of 1087 checks passed
@michaelklishin michaelklishin deleted the mergify/bp/v4.1.x/pr-14970 branch November 19, 2025 23:05
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

Successfully merging this pull request may close these issues.

3 participants