Issue 1:
Greetings and congrats again for this amazingly well documented library, I'm happy Twitter made me discover this !

So I decided to dive a little bit into it, and I was in particular interested in the Starlette DatabaseMiddleware.

I then cloned the related test in Starlette and reworked it using FastAPI here: https://github.com/euri10/fastapi/blob/dbmiddleware/tests/test_dbmiddleware.py

so in this test we got:

one starlette instance of Starlette starlette=Starlette() that makes the very same tests as in the test_database mentionned aboveand

one fastapi instance of FastAPI fastapi=FastAPI(), whose routes have been adapted by me to take the new "framework" into account (mainly switching to app.get and app.post instead of app.route, making use of pydantic models etc,....)

Each instance is tested separately in a class, namely class TestStarletteStyle(): and class TestFastAPIStyle():

Obviously TestStarletteStyle passes like in the original file.

Interestingly if you change starlette=Starlette() to starlette=FastAPI() TestStarletteStyle passes also, which makes sense since if I got it correctly a fastapi.post is the same as a fastapi.route, methods=["POST"]

However TestFastAPIStyle fails at various points, all tests fails but not all asserts:

fails here as while the previous RuntimeError has been raised, the entry has been put in the database, while in the TestStarletteStyle the RuntimeError prevented this, is seems related to the rollback_on_shutdown=True that would not have been taken into account if i understand correctly, but take this with caution I'm brand new to your code and starlette's one.

fails here too, and looking at what we got in db (5 entries instead of 2 in the test) it seems also related to a rollback not made.

finally fails here too, and we got 6 entries in db instead of 1 tested, same intuition.

So there's seem to be something incorrect with the rollback setting, happy to dig further but you surely have ideas, if making a PR with my failing branch is ok let me know

Issue 2:
First check

I added a very descriptive title to this issue.

I used the GitHub search to find a similar issue and didn't find it.

I searched the FastAPI documentation, with the integrated search.

I already searched in Google "How to X in FastAPI" and didn't find any information.

I already read and followed all the tutorial in the docs and didn't find an answer.

I already checked if it is not related to FastAPI but to Pydantic.

I already checked if it is not related to FastAPI but to Swagger UI.

I already checked if it is not related to FastAPI but to ReDoc.

After submitting this, I commit to one of:

Read open issues with questions until I find 2 issues where I can help someone and add a comment to help there.

I already hit the "watch" button in this repository to receive notifications and I commit to help at least 2 people that ask questions in the future.

Implement a Pull Request for a confirmed bug.

Example

Here's a self-contained, minimal, reproducible, example with my use case:

from typing import List, Optional

from fastapi import FastAPI, Header

app = FastAPI()

@app.get("/items/")
async def read_items(x_token: Optional[List[str]] = Header(None)):

return {"X-Token values": x_token}

Description

What I did with HTTPie(and same as what Swagger did with curl):

$ http -v :8000/items/ X-Token:first,second
GET /items/ HTTP/1.1
Accept: */*
Accept-Encoding: gzip, deflate
Connection: keep-alive
Host: localhost:8000
User-Agent: HTTPie/2.3.0
X-Token: first,second

It returns a JSON with

{
"X-Token values": [
"first,second"
]
}

But I expected it to return:

{
"X-Token values": [
"first",
"second"
]
}

Environment

OS: macOS 11.2.3

FastAPI Version: 0.63.0

Python version: 3.9.4

Additional context

From Header Parameters docs, it said FastAPI can receive multiple values for a single header. However, It's not working properly. Thus, I had to pop it and split it with ,.

It's not a big deal, but I think the official doc must have reliability. Frankly, I'm confused this is a bug or a feature...