Skip to content

preferredFormat() and Content-Type merge in browser #21

Open
@MacloudTP

Description

@MacloudTP

Hi,

while testing ->preferredFormat() with Chrome I got an ERR_INVALID_SIGNED_EXCHANGE error.

The response had a bad content-type, as it uses the full Accept-Header, e.g.

text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9; charset=UTF-8

Of course, for API requests only sending an Accept-Header like application/xml or application/json the original code works.

I needed to merge the fixed xml / json content-types as done in other places in the code:

if (Str::contains($request->headers->get('Accept'), 'xml')) {
    return $this->xml($data, $status, array_merge($headers, ['Content-Type' => 'application/xml']), $xmlRoot, $encoding);
}
return $this->json($data, $status, array_merge($headers, ['Content-Type' => 'application/json']));

Thanks for considering the change in the repository.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions