Skip to content

Problem with Content negotiation - Status code #106

Description

@filhodanuvem

I'm using the latest Respect/Rest and probably I found a problem with content negotiation.

<?php

require __DIR__.'/vendor/autoload.php';

$r = new Respect\Rest\Router;
$contentNegotiation = [
   'text/html' => 'var_dump',
];
$r->get('/*/*', function(){
   return ['respect' => 'Ola!']; 
})->accept($contentNegotiation); 

$r->run();

If I send a request with header 'Accept: text/html' it works but if I send 'Accept: application/json', the application returns http 405 status code instead of 406.

I watch the source code, and at first the correct header is setted

protected function notifyDeclined($requested, $provided, Request $request, $params)
{
        $this->negotiated = false;
        header('HTTP/1.1 406');
}

Next, the status code is overwritten

protected function informMethodNotAllowed(array $allowedMethods)
    {
        header('HTTP/1.1 405');

        if (!$allowedMethods) {
            return;
        }

        $this->informAllowedMethods($allowedMethods);
        $this->request->route = null;
    }

I hope fix it and send a PR soon, meanwhile the @Respect team could help me too about how do it in better way :)

☁️

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions