зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1657445 - [wptserve] Content-Length header missing when response is a file object r=jgraham
Differential Revision: https://phabricator.services.mozilla.com/D86052
This commit is contained in:
Родитель
4bf4c20d40
Коммит
ee5bdd9c60
|
@ -2,6 +2,7 @@ from collections import OrderedDict
|
|||
from datetime import datetime, timedelta
|
||||
from io import BytesIO
|
||||
import json
|
||||
import os
|
||||
import socket
|
||||
import uuid
|
||||
|
||||
|
@ -711,10 +712,15 @@ class ResponseWriter(object):
|
|||
if not self._seen_header(name):
|
||||
self.write_header(name, f())
|
||||
|
||||
if (isinstance(self._response.content, (binary_type, text_type)) and
|
||||
not self._seen_header("content-length")):
|
||||
#Would be nice to avoid double-encoding here
|
||||
self.write_header("Content-Length", len(self.encode(self._response.content)))
|
||||
if not self._seen_header("content-length"):
|
||||
content_length = None
|
||||
if isinstance(self._response.content, (binary_type, text_type)):
|
||||
#Would be nice to avoid double-encoding here
|
||||
content_length = len(self.encode(self._response.content))
|
||||
elif isinstance(self._response.content, file):
|
||||
content_length = os.fstat(self._response.content.fileno()).st_size
|
||||
if content_length:
|
||||
self.write_header("Content-Length", content_length)
|
||||
|
||||
def end_headers(self):
|
||||
"""Finish writing headers and write the separator.
|
||||
|
|
Загрузка…
Ссылка в новой задаче