Coverage for /Users/davegaeddert/Development/dropseed/plain/plain/plain/internal/middleware/headers.py: 100%

1 from plain.runtime import settings

2

3

4 class DefaultHeadersMiddleware:

5 def __init__(self, get_response):

6 self.get_response = get_response

7

8 def __call__(self, request):

9 response = self.get_response(request)

10

11 for header, value in settings.DEFAULT_RESPONSE_HEADERS.items():

12 response.headers.setdefault(header, value)

13

14 # Add the Content-Length header to non-streaming responses if not

15 # already set.

16 if not response.streaming and not response.has_header("Content-Length"):

17 response.headers["Content-Length"] = str(len(response.content))

18

19 return response