dingo / dingo/api

Accept header overwritten on internal requests

Open
#1,228 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
PHP
Stars
9.4k
Forks
1.3k
PR merge metrics
No merged PRs in 30d

Description

I am using the Dispatcher to make internal API calls. One of them has the ability to return XML by checking the Accept header. This does work with internal requests since Dispatcher always sets the Accept after the defined headers have been set. So it gets overwritten.

`$this->dispatcher->header('Accept', 'application/xml')->header('foo', 'bar')->get('/api/v1/endpoint');`

```
array:6 [
"host" => []
"user-agent" => array:1 [
0 => "Symfony/3.X"
]
"accept" => array:1 [
0 => "application/x..v1+json" <-- Should be 'application/xml'
]
"accept-language" => array:1 [
0 => "en-us,en;q=0.5"
]
"accept-charset" => array:1 [
0 => "ISO-8859-1,utf-8;q=0.7,*;q=0.7"
]
"foo" => array:1 [
0 => "bar"
]
]
```

Problem would be solved by moving the separate line setting the default Accept header before adding the custom headers. The default would be still there, but a custom Accept header could be actually set. I can make a pull request if needed.

https://github.com/dingo/api/blob/master/src/Dispatcher.php#L481-L485

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.