Skip to content

Conversation

@mergify
Copy link

@mergify mergify bot 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.

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).

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 be75522)

# Conflicts:
#	release-notes/4.3.0.md
- 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)
Replace manual header setting with charsets_provided/2 callback to
let Cowboy handle charset negotiation automatically.

(cherry picked from commit c1cc495)
@mergify mergify bot added the conflicts label Nov 18, 2025
@mergify
Copy link
Author

mergify bot commented Nov 18, 2025

Cherry-pick of be75522 has failed:

On branch mergify/bp/v4.2.x/pr-14966
Your branch is ahead of 'origin/v4.2.x' by 1 commit.
  (use "git push" to publish your local commits)

You are currently cherry-picking commit be7552257.
  (fix conflicts and run "git cherry-pick --continue")
  (use "git cherry-pick --skip" to skip this patch)
  (use "git cherry-pick --abort" to cancel the cherry-pick operation)

Unmerged paths:
  (use "git add/rm <file>..." as appropriate to mark resolution)
	deleted by us:   release-notes/4.3.0.md

no changes added to commit (use "git add" and/or "git commit -a")

To fix up this pull request, you can check it out locally. See documentation: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally

@michaelklishin michaelklishin added this to the 4.2.2 milestone Nov 19, 2025
@michaelklishin michaelklishin merged commit 0597f88 into v4.2.x Nov 19, 2025
574 of 575 checks passed
@michaelklishin michaelklishin deleted the mergify/bp/v4.2.x/pr-14966 branch November 19, 2025 04:00
@michaelklishin
Copy link
Collaborator

@Mergifyio backport v4.1.x

@mergify
Copy link
Author

mergify bot commented Nov 19, 2025

backport v4.1.x

✅ Backports have been created

mergify bot pushed a commit that referenced this pull request Nov 19, 2025
(cherry picked from commit f5a7454)
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.

3 participants