<h3 dir="auto">Is your feature request related to a problem</h3>
<p dir="auto">I'd like to be able inject a response header from inside a dependency, as we can from path operation functions. The dependency injection system should operate the same for dependency functions as for path operation functions.</p>
<p dir="auto">Example code:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="from datetime import datetime

from fastapi import FastAPI, Depends
from starlette.responses import Response
from starlette.testclient import TestClient

app = FastAPI()


def cache_control(response: Response):
    response.headers.setdefault('last-modified', datetime.now().isoformat())


def other_dependency():
    return {'foo': 'bar'}


@app.get('/doc', dependencies=[Depends(cache_control)])
def get_doc(other: dict = Depends(other_dependency)):
    document = {'other': other}
    return document


if __name__ == '__main__':
    client = TestClient(app=app)
    print(client.get('/doc').headers)"><pre class="notranslate"><code class="notranslate">from datetime import datetime

from fastapi import FastAPI, Depends
from starlette.responses import Response
from starlette.testclient import TestClient

app = FastAPI()


def cache_control(response: Response):
    response.headers.setdefault('last-modified', datetime.now().isoformat())


def other_dependency():
    return {'foo': 'bar'}


@app.get('/doc', dependencies=[Depends(cache_control)])
def get_doc(other: dict = Depends(other_dependency)):
    document = {'other': other}
    return document


if __name__ == '__main__':
    client = TestClient(app=app)
    print(client.get('/doc').headers)
</code></pre></div>
<p dir="auto">The result of the above code is that the last-modified header is duplicated because the dependency resolver expects that only the path operation function will try to add headers, and only once. Adding additional dependencies causes exponential duplication.</p>
<p dir="auto">Headers get merged here:<br>
<a href="https://github.com/tiangolo/fastapi/blob/master/fastapi/dependencies/utils.py#L489">https://github.com/tiangolo/fastapi/blob/master/fastapi/dependencies/utils.py#L489</a></p>
<p dir="auto">At that point in the above scenario, <code class="notranslate">response is sub_response</code> is <code class="notranslate">True</code> -- they are the same object.</p>
<h3 dir="auto">Description</h3>
<p dir="auto">This is similar to the question <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="526375835" data-permission-text="Title is private" data-url="https://github.com/tiangolo/fastapi/issues/724" data-hovercard-type="issue" data-hovercard-url="/tiangolo/fastapi/issues/724/hovercard" href="https://github.com/tiangolo/fastapi/issues/724#issue-526375835">#724 (comment)</a> but instead of extra parameters, how do I raise an error if multiple of the same valid parameters are provided.</p>
<p dir="auto"><strong>Example:</strong></p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="from fastapi import FastAPI
from pydantic import BaseModel

app = FastAPI()

class UpdateModel(BaseModel):
    name: str
    class Config:
        extra = &quot;forbid&quot;

@app.post(&quot;/items/&quot;)
async def update(item: UpdateModel):
    # do smth with item.name"><pre class="notranslate"><code class="notranslate">from fastapi import FastAPI
from pydantic import BaseModel

app = FastAPI()

class UpdateModel(BaseModel):
    name: str
    class Config:
        extra = "forbid"

@app.post("/items/")
async def update(item: UpdateModel):
    # do smth with item.name
</code></pre></div>
<p dir="auto">If I send {"name": "FOO", "name": "BAR"} the second "name" is used for item (i.e. item.name = "BAR")<br>
How can I raise an error with my pydantic model so this is rejected?  The extra = "forbid" does not work for duplicates.</p>
<p dir="auto">Thanks</p>
<h3 dir="auto">Operating System</h3>
<p dir="auto">Windows</p>
<h3 dir="auto">Operating System Details</h3>
<p dir="auto"><em>No response</em></p>
<h3 dir="auto">FastAPI Version</h3>
<p dir="auto">0.66.0</p>
<h3 dir="auto">Python Version</h3>
<p dir="auto">3.9.1</p>
<h3 dir="auto">Additional Context</h3>
<p dir="auto"><em>No response</em></p>