joomla-cms icon indicating copy to clipboard operation
joomla-cms copied to clipboard

Fix `content-type` header to `application/json`

Open rubenferreira97 opened this issue 1 year ago • 3 comments

Pull Request for Issue #43641.

Summary of Changes

JsonDocument in Joomla 4.4.5 wrongly sets text/plain to all browsers (tested on Edge, Firefox and Chrome). Browsers do not usually send application/json, instead they send */* with some lower priority.

Note: Joomla 5 already fixed this, so this change needs to be merged to Joomla 4 (maybe Joomla 4.4.6?).

Testing Instructions

Ping and API endpoint that extends JsonDocument. In my case I am returning a normal json response instead of a json:api.

Actual result BEFORE applying this Pull Request

Ping an API endpoint like localhost/api/index.php/v1/example: Content-Type: text/plain; charset=utf-8

Expected result AFTER applying this Pull Request

Ping an API endpoint like localhost/api/index.php/v1/example: Content-Type: application/json; charset=utf-8

Link to documentations

Please select:

  • [ ] Documentation link for docs.joomla.org:

  • [x] No documentation changes for docs.joomla.org needed

  • [ ] Pull Request link for manual.joomla.org:

  • [x] No documentation changes for manual.joomla.org needed

rubenferreira97 avatar Jun 21 '24 10:06 rubenferreira97

Can you reference the pr which fixed this issue already in 5. The change here is a BC break, so not sure if the need to fix it weight's higher than the BC policy.

laoneo avatar Jun 21 '24 13:06 laoneo

@laoneo The PR which fixed this issue was https://github.com/joomla/joomla-cms/pull/39397. IMO this is a bug that should be fixed since JsonDocument should always return application/json by default. Even the IE9 fix was a hacky workaround. Don't know about Joomla BC policy, but are people really expecting this and working around this behavior?

rubenferreira97 avatar Jun 21 '24 14:06 rubenferreira97

Problem is that this behavior did exist now for a long time. Changing it in a patch release might cause unexpected issues in extensions using that class as it belongs to the public API. We will discuss it in maintainers group and report back.

laoneo avatar Jun 21 '24 14:06 laoneo

Closing this PR, since 4.4 is in security mode only and it's fixed in 5.x

HLeithner avatar Nov 15 '24 13:11 HLeithner