Respond_to: differentiate */* vs. other formats?

We have an API endpoint called by a legacy client with Accept: */* (1), in which case it should return JSON. This API also needs to respond differently to turbo_stream requests. How can these be differentiated?

In the following snippet, the legacy client is sent the turbo_stream response because */* matches every mime type (including turbo_stream), which is not what we want:

respond_to do |format|
  format.any { render ... }

(1) No header is actually sent, which is interpreted as Accept: */*.

Maybe you could use turbo_frame_request?

Or set the adequate HTTP header (looks like it’s not possible in your case)

Thanks @kawsay, indeed I can’t set the header as this is to handle calls from a legacy client which is already in the wild. As for your suggestion, what I was looking for was a way to be able to use respond_to. Here is my workaround for now:

if request.format.json? || request.format == "*/*"
  render json: ...
  render turbo_stream: ...