openstreetmap / openstreetmap-website

The Rails application that powers OpenStreetMap
https://www.openstreetmap.org/
GNU General Public License v2.0
2.17k stars 910 forks source link

`/messages/{id}/mark?mark={unread/read}` returns HTML code #5222

Closed Dimitar5555 closed 1 week ago

Dimitar5555 commented 1 week ago

URL

https://www.openstreetmap.org/messages/inbox

How to reproduce the issue?

  1. Have at least 1 message in the inbox
  2. Mark it as read/unread
  3. Notice that two requests are made at the same time (one POST and one GET).

The POST request goes to https://www.openstreetmap.org/messages/{id}/mark?mark=unread, while the GET request goes to https://www.openstreetmap.org/messages/inbox. Both requests return the same HTML code, which seems a bit wasteful on server resources if both are generated independently.

The most logical solution would be to change the response body of the POST request to have some short status code/text instead of the whole page HTML (assuming that won't break the turbo integration).

Screenshot(s) or anything else?

2024-09-18_00-39

mmd-osm commented 1 week ago

This seems a bit odd. The POST request already returns an HTTP return code 303 along with a location: https://www.openstreetmap.org/messages/inbox header for the redirect.

According to https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/303 the browser is supposed to ignore the payload in the body and follow the redirect. I'm not clear why Rails is sending the payload as well in this case, which seems a bit pointless.

Code in question: https://github.com/openstreetmap/openstreetmap-website/blob/master/app/controllers/messages_controller.rb#L141-L145

AntonKhorev commented 1 week ago

I'm not convinced that POST actually sends the response body even though Firefox shows it. Compare your "receiving" timings for POST and GET.

mmd-osm commented 1 week ago

@AntonKhorev : you're right. I checked the response in wireshark, and the POST request returns HTTP 303 with an empty response body.

Closing here, since there's no issue really.