Since the last updates, I got a "No matching accepted Response format could be determined" when I call a route with an url starting with /api.
Here is the configuration:
# FOSRest Configuration
fos_rest:
param_fetcher_listener: force
routing_loader:
default_format: json
access_denied_listener:
json: true
format_listener:
rules:
- { path: ^/api, priorities: ['json', 'html', '*/*'], fallback_format: json, prefer_extension: true }
- { path: ^/, priorities: ['html', '*/*'], fallback_format: html, prefer_extension: true }
I didn't change anything.
can you also paste some information on the request?
Here is my Request object:
array (size=20)
'attributes' =>
object(Symfony\Component\HttpFoundation\ParameterBag)[9]
protected 'parameters' =>
array (size=5)
'_controller' => string 'My\Bundle\Controller\ParticipationController::cgetAction' (length=77)
'_format' => string 'json' (length=4)
'_route' => string 'api_participation_get_participations' (length=36)
'_route_params' =>
array (size=1)
...
'media_type' => string '*/*' (length=3)
'request' =>
object(Symfony\Component\HttpFoundation\ParameterBag)[7]
protected 'parameters' =>
array (size=0)
empty
'query' =>
object(Symfony\Component\HttpFoundation\ParameterBag)[8]
protected 'parameters' =>
array (size=1)
'search' => string '060606' (length=18)
'server' =>
object(Symfony\Component\HttpFoundation\ServerBag)[12]
protected 'parameters' =>
array (size=32)
'REDIRECT_STATUS' => string '200' (length=3)
'HTTP_HOST' => string 'domain.fr' (length=38)
'HTTP_CONNECTION' => string 'keep-alive' (length=10)
'HTTP_CACHE_CONTROL' => string 'no-cache' (length=8)
'HTTP_USER_AGENT' => string 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/30.0.1599.114 Chrome/30.0.1599.114 Safari/537.36' (length=135)
'HTTP_ACCEPT' => string '*/*' (length=3)
'HTTP_ACCEPT_ENCODING' => string 'gzip,deflate,sdch' (length=17)
'HTTP_ACCEPT_LANGUAGE' => string 'fr-FR,fr;q=0.8,en-US;q=0.6,en;q=0.4' (length=35)
'HTTP_COOKIE' => string 'PHPSESSID=apcbqs4vd80npag4lnldb' (length=36)
'PATH' => string '/usr/local/bin:/usr/bin:/bin' (length=28)
'SERVER_SIGNATURE' => string '<address>Apache/2.2.22 (Ubuntu) Server at domain.fr Port 80</address>
' (length=99)
'SERVER_SOFTWARE' => string 'Apache/2.2.22 (Ubuntu)' (length=22)
'SERVER_NAME' => string 'domain.fr' (length=38)
'SERVER_ADDR' => string '127.0.0.1' (length=9)
'SERVER_PORT' => string '80' (length=2)
'REMOTE_ADDR' => string '127.0.0.1' (length=9)
'DOCUMENT_ROOT' => string '/path/web' (length=47)
'SERVER_ADMIN' => string '[no address given]' (length=18)
'SCRIPT_FILENAME' => string '/path/web/app_dev.php' (length=59)
'REMOTE_PORT' => string '51924' (length=5)
'REDIRECT_QUERY_STRING' => string 'search=060606' (length=25)
'REDIRECT_URL' => string '/api/participations' (length=19)
'GATEWAY_INTERFACE' => string 'CGI/1.1' (length=7)
'SERVER_PROTOCOL' => string 'HTTP/1.1' (length=8)
'REQUEST_METHOD' => string 'GET' (length=3)
'QUERY_STRING' => string 'search=060606' (length=25)
'REQUEST_URI' => string '/api/participations?search=060606' (length=45)
'SCRIPT_NAME' => string '/app_dev.php' (length=12)
'PHP_SELF' => string '/app_dev.php' (length=12)
'REQUEST_TIME_FLOAT' => float 1386751759.939
'REQUEST_TIME' => int 1386751759
'files' =>
object(Symfony\Component\HttpFoundation\FileBag)[11]
protected 'parameters' =>
array (size=0)
empty
'cookies' =>
object(Symfony\Component\HttpFoundation\ParameterBag)[10]
protected 'parameters' =>
array (size=1)
'PHPSESSID' => string 'apcbqs4vd80npag4lnldb' (length=26)
'headers' =>
object(Symfony\Component\HttpFoundation\HeaderBag)[13]
protected 'headers' =>
array (size=10)
'host' =>
array (size=1)
...
'connection' =>
array (size=1)
...
'cache-control' =>
array (size=1)
...
'user-agent' =>
array (size=1)
...
'accept' =>
array (size=1)
...
'accept-encoding' =>
array (size=1)
...
'accept-language' =>
array (size=1)
...
'cookie' =>
array (size=1)
...
'x-php-ob-level' =>
array (size=1)
...
protected 'cacheControl' =>
array (size=1)
'no-cache' => boolean true
'�*�content' => null
'�*�languages' => null
'�*�charsets' => null
'�*�acceptableContentTypes' => null
'�*�pathInfo' => string '/api/participations' (length=19)
'�*�requestUri' => string '/api/participations?search=060606' (length=45)
'�*�baseUrl' => string '' (length=0)
'�*�basePath' => null
'�*�method' => string 'GET' (length=3)
'�*�format' => null
'�*�session' =>
object(Symfony\Component\HttpFoundation\Session\Session)[140]
protected 'storage' =>
object(Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage)[139]
protected 'bags' =>
array (size=2)
...
protected 'started' => boolean false
protected 'closed' => boolean false
protected 'saveHandler' =>
object(Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy)[136]
...
protected 'metadataBag' =>
object(Symfony\Component\HttpFoundation\Session\Storage\MetadataBag)[137]
...
private 'flashName' => string 'flashes' (length=7)
private 'attributeName' => string 'attributes' (length=10)
'�*�locale' => null
'�*�defaultLocale' => string 'en' (length=2)
array (size=20)
'attributes' =>
object(Symfony\Component\HttpFoundation\ParameterBag)[86]
protected 'parameters' =>
array (size=6)
'_controller' => string 'twig.controller.exception:showAction' (length=36)
'exception' =>
object(Symfony\Component\HttpKernel\Exception\FlattenException)[95]
...
'logger' =>
object(Symfony\Bridge\Monolog\Logger)[195]
...
'format' => string 'json' (length=4)
'_format' => string 'json' (length=4)
'media_type' => string '*/*' (length=3)
'request' =>
object(Symfony\Component\HttpFoundation\ParameterBag)[92]
protected 'parameters' =>
array (size=0)
empty
'query' =>
object(Symfony\Component\HttpFoundation\ParameterBag)[93]
protected 'parameters' =>
array (size=1)
'search' => string '060606' (length=18)
'server' =>
object(Symfony\Component\HttpFoundation\ServerBag)[88]
protected 'parameters' =>
array (size=32)
'REDIRECT_STATUS' => string '200' (length=3)
'HTTP_HOST' => string 'domain.fr' (length=38)
'HTTP_CONNECTION' => string 'keep-alive' (length=10)
'HTTP_CACHE_CONTROL' => string 'no-cache' (length=8)
'HTTP_USER_AGENT' => string 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/30.0.1599.114 Chrome/30.0.1599.114 Safari/537.36' (length=135)
'HTTP_ACCEPT' => string '*/*' (length=3)
'HTTP_ACCEPT_ENCODING' => string 'gzip,deflate,sdch' (length=17)
'HTTP_ACCEPT_LANGUAGE' => string 'fr-FR,fr;q=0.8,en-US;q=0.6,en;q=0.4' (length=35)
'HTTP_COOKIE' => string 'PHPSESSID=apcbqs4vd80npag4lnldb' (length=36)
'PATH' => string '/usr/local/bin:/usr/bin:/bin' (length=28)
'SERVER_SIGNATURE' => string '<address>Apache/2.2.22 (Ubuntu) Server at domain.fr Port 80</address>
' (length=99)
'SERVER_SOFTWARE' => string 'Apache/2.2.22 (Ubuntu)' (length=22)
'SERVER_NAME' => string 'domain.fr' (length=38)
'SERVER_ADDR' => string '127.0.0.1' (length=9)
'SERVER_PORT' => string '80' (length=2)
'REMOTE_ADDR' => string '127.0.0.1' (length=9)
'DOCUMENT_ROOT' => string '/path/web' (length=47)
'SERVER_ADMIN' => string '[no address given]' (length=18)
'SCRIPT_FILENAME' => string '/path/web/app_dev.php' (length=59)
'REMOTE_PORT' => string '51924' (length=5)
'REDIRECT_QUERY_STRING' => string 'search=060606' (length=25)
'REDIRECT_URL' => string '/api/participations' (length=19)
'GATEWAY_INTERFACE' => string 'CGI/1.1' (length=7)
'SERVER_PROTOCOL' => string 'HTTP/1.1' (length=8)
'REQUEST_METHOD' => string 'GET' (length=3)
'QUERY_STRING' => string 'search=060606' (length=25)
'REQUEST_URI' => string '/api/participations?search=060606' (length=45)
'SCRIPT_NAME' => string '/app_dev.php' (length=12)
'PHP_SELF' => string '/app_dev.php' (length=12)
'REQUEST_TIME_FLOAT' => float 1386751759.939
'REQUEST_TIME' => int 1386751759
'files' =>
object(Symfony\Component\HttpFoundation\FileBag)[89]
protected 'parameters' =>
array (size=0)
empty
'cookies' =>
object(Symfony\Component\HttpFoundation\ParameterBag)[90]
protected 'parameters' =>
array (size=1)
'PHPSESSID' => string 'apcbqs4vd80npag4lnldb' (length=26)
'headers' =>
object(Symfony\Component\HttpFoundation\HeaderBag)[87]
protected 'headers' =>
array (size=10)
'host' =>
array (size=1)
...
'connection' =>
array (size=1)
...
'cache-control' =>
array (size=1)
...
'user-agent' =>
array (size=1)
...
'accept' =>
array (size=1)
...
'accept-encoding' =>
array (size=1)
...
'accept-language' =>
array (size=1)
...
'cookie' =>
array (size=1)
...
'x-php-ob-level' =>
array (size=1)
...
protected 'cacheControl' =>
array (size=1)
'no-cache' => boolean true
'�*�content' => null
'�*�languages' => null
'�*�charsets' => null
'�*�acceptableContentTypes' => null
'�*�pathInfo' => string '/api/participations' (length=19)
'�*�requestUri' => string '/api/participations?search=060606' (length=45)
'�*�baseUrl' => string '' (length=0)
'�*�basePath' => null
'�*�method' => string 'GET' (length=3)
'�*�format' => string 'json' (length=4)
'�*�session' =>
object(Symfony\Component\HttpFoundation\Session\Session)[140]
protected 'storage' =>
object(Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage)[139]
protected 'bags' =>
array (size=2)
...
protected 'started' => boolean false
protected 'closed' => boolean false
protected 'saveHandler' =>
object(Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy)[136]
...
protected 'metadataBag' =>
object(Symfony\Component\HttpFoundation\Session\Storage\MetadataBag)[137]
...
private 'flashName' => string 'flashes' (length=7)
private 'attributeName' => string 'attributes' (length=10)
'�*�locale' => null
'�*�defaultLocale' => string 'en' (length=2)
If I call /api/participations.json?search=060606 it works of course.
I investigated a bit on my problem. Seems the new system works differently with the accept header. When there is no Accept header containing, for instance application/json, a */* is returned by the following code (with my configuration):
// FOS\RestBundle\Util\FormatNegotiator
/**
* Detect the request format based on the priorities and the Accept header
*
* @param Request $request The request
* @return void|string The format string
*/
public function getBestMediaType(Request $request)
{
// ...
$mimeTypes = $this->formatNegotiator->normalizePriorities($options['priorities']);
$mediaType = $this->formatNegotiator->getBest($acceptHeader, $mimeTypes);
if (null !== $mediaType) {
return $mediaType->getValue(); // return '*/*'
}
if (isset($options['fallback_format'])) {
// if false === fallback_format then we fail here instead of considering more rules
if (false === $options['fallback_format']) {
return null;
}
// stop looking at rules since we have a fallback defined
return $request->getMimeType($options['fallback_format']);
}
// ...
Before, the format variable was null and the format was taken on the fallback_format:
// FOS\RestBundle\Util\FormatNegotiator
/**
* Detect the request format based on the priorities and the Accept header
*
* @param Request $request The request
* @return void|string The format string
*/
public function getBestMediaType(Request $request)
{
// ...
$format = $this->formatNegotiator->getBestFormat($acceptHeader, $options['priorities']);
if (null !== $format) {
return $format;
}
if (isset($options['fallback_format'])) {
// if false === fallback_format then we fail here instead of considering more rules
if (false === $options['fallback_format']) {
return null;
}
// stop looking at rules since we have a fallback defined
return $request->getMimeType($options['fallback_format']);
}
// ...
So, I think I should be stricter and set my Accept header.
Ah I see .. I need to check this out as it might be an unwanted regression.
shit should have looked here before :-)
having the same, there seems not to be any fallback for sending
Accept: */*
headers.
My config is:
fos_rest:
...
format_listener:
rules:
- { path: '^/api', priorities: ['json', 'html'], fallback_format: html, prefer_extension: true }
- { path: '^/', priorities: [ 'html', '*/*'], fallback_format: ~, prefer_extension: true }
...
in https://github.com/liip-forks/symfony-standard/blob/techtalk/app/config/config.yml the last line does not contain
'*/*'
does the techtalk sandbox not support _wdt cause this is issueing the request:
Request URL:http://localhost/app_dev.php/_wdt/81b0eb
Request Method:GET
Status Code:406 Not Acceptable
Request Headersview source
Accept:*/*
Accept-Encoding:gzip,deflate,sdch
Accept-Language:de-DE,de;q=0.8,en-US;q=0.6,en;q=0.4,en-GB;q=0.2
Cache-Control:max-age=0
Connection:keep-alive
Cookie:__uvt=; jstree_open=; jstree_load=; uvts=xHNDAjKm3f2wIAe; PHPSESSID=o5act9hg9slk2s6sbej9ukftg3
Host:local.booksync.net:8081
Referer:http://local.booksync.net:8081/app_dev.php/feed
User-Agent:Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.57 Safari/537.36
X-Requested-With:XMLHttpRequest
or is there any other way implemented i didnt see (.htaccess does not change the request in that way or?)
btw this is probably the same as the error i am having now for fosrouting request:
Request URL:http://local.booksync.net:8081/app_dev.php/js/routing?callback=fos.Router.setData
Request Method:GET
Status Code:500 Internal Server Error
Request Headersview source
Accept:*/*
Accept-Encoding:gzip,deflate,sdch
Accept-Language:de-DE,de;q=0.8,en-US;q=0.6,en;q=0.4,en-GB;q=0.2
Cache-Control:max-age=0
Connection:keep-alive
Cookie:__uvt=; jstree_open=; jstree_load=; uvts=xHNDAjKm3f2wIAe; PHPSESSID=i43li1ogubomgkm25nq4u2okc3
Host:local.booksync.net:8081
Referer:http://local.booksync.net:8081/app_dev.php/feed
User-Agent:Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.57 Safari/537.36
Most helpful comment
shit should have looked here before :-)
having the same, there seems not to be any fallback for sending
headers.
My config is:
in https://github.com/liip-forks/symfony-standard/blob/techtalk/app/config/config.yml the last line does not contain
does the techtalk sandbox not support _wdt cause this is issueing the request:
or is there any other way implemented i didnt see (.htaccess does not change the request in that way or?)