Problem with Content negotiation - Status code
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 48/100
Research direction
Reproduce the example in the issue with Accept: text/html and Accept: application/json. Read library/Respect/Rest/Routines/AbstractAccept.php around notifyDeclined and library/Respect/Rest/Router.php around informMethodNotAllowed to trace the status overwrite. Done means an unsupported representation returns HTTP 406 rather than HTTP 405.
Written by the indexing model from the issue text.
Description
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 :)
☁️
- Dominant language
- PHP
- Stars
- 605
- Forks
- 100
- PR merge metrics
- No merged PRs in 30d
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from Respect/Rest
-
Project Status Open
Difficulty 5/5 Over a week Newbie friendliness 10/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 52/100
-
New Roadmap Open
Difficulty 5/5 Over a week Newbie friendliness 15/100
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
-
bug
Difficulty 4/5 3-5 days Newbie friendliness 35/100
Similar issues
-
tooling
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
UX
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
ProfessionalWiki/NeoWiki#1525 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
bug customer-reported
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
MagnaCapax/PMSS#949 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
Automattic/static-site-importer#1829 ·