Skip to content

Expected 406 on Accept: application/json, got 200 OK #184

Closed
@preliot

Description

@preliot

I'm using postman to test our new API.

Noticed that when i set Accept: application/json, the API still works. Every other Accept header, not being application/vnd.api+json, will return a 406 as expected. This should not happen, see https://laraveljsonapi.io/docs/2.0/requests/compliance.html#accept-header.

This is correct:

LaravelJsonApi\Laravel\Http\Requests\ResourceQuery.php

/**
     * @var string[]
     */
    protected array $mediaTypes = [
        self::JSON_API_MEDIA_TYPE,
    ];

This seems to produce the incorrect result:

/**
     * @return bool
     */
    protected function isAcceptableMediaType(): bool
    {
        return $this->accepts($this->mediaTypes());
    }

Illuminate\Http\Concerns\InteractsWithContentTypes.php > matchesType() assumes application/json and application/vnd.api+json are identical.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions