base_response.py 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700
  1. import warnings
  2. from .._compat import integer_types
  3. from .._compat import string_types
  4. from .._compat import text_type
  5. from .._compat import to_bytes
  6. from .._compat import to_native
  7. from ..datastructures import Headers
  8. from ..http import dump_cookie
  9. from ..http import HTTP_STATUS_CODES
  10. from ..http import remove_entity_headers
  11. from ..urls import iri_to_uri
  12. from ..urls import url_join
  13. from ..utils import get_content_type
  14. from ..wsgi import ClosingIterator
  15. from ..wsgi import get_current_url
  16. def _run_wsgi_app(*args):
  17. """This function replaces itself to ensure that the test module is not
  18. imported unless required. DO NOT USE!
  19. """
  20. global _run_wsgi_app
  21. from ..test import run_wsgi_app as _run_wsgi_app
  22. return _run_wsgi_app(*args)
  23. def _warn_if_string(iterable):
  24. """Helper for the response objects to check if the iterable returned
  25. to the WSGI server is not a string.
  26. """
  27. if isinstance(iterable, string_types):
  28. warnings.warn(
  29. "Response iterable was set to a string. This will appear to"
  30. " work but means that the server will send the data to the"
  31. " client one character at a time. This is almost never"
  32. " intended behavior, use 'response.data' to assign strings"
  33. " to the response object.",
  34. stacklevel=2,
  35. )
  36. def _iter_encoded(iterable, charset):
  37. for item in iterable:
  38. if isinstance(item, text_type):
  39. yield item.encode(charset)
  40. else:
  41. yield item
  42. def _clean_accept_ranges(accept_ranges):
  43. if accept_ranges is True:
  44. return "bytes"
  45. elif accept_ranges is False:
  46. return "none"
  47. elif isinstance(accept_ranges, text_type):
  48. return to_native(accept_ranges)
  49. raise ValueError("Invalid accept_ranges value")
  50. class BaseResponse(object):
  51. """Base response class. The most important fact about a response object
  52. is that it's a regular WSGI application. It's initialized with a couple
  53. of response parameters (headers, body, status code etc.) and will start a
  54. valid WSGI response when called with the environ and start response
  55. callable.
  56. Because it's a WSGI application itself processing usually ends before the
  57. actual response is sent to the server. This helps debugging systems
  58. because they can catch all the exceptions before responses are started.
  59. Here a small example WSGI application that takes advantage of the
  60. response objects::
  61. from werkzeug.wrappers import BaseResponse as Response
  62. def index():
  63. return Response('Index page')
  64. def application(environ, start_response):
  65. path = environ.get('PATH_INFO') or '/'
  66. if path == '/':
  67. response = index()
  68. else:
  69. response = Response('Not Found', status=404)
  70. return response(environ, start_response)
  71. Like :class:`BaseRequest` which object is lacking a lot of functionality
  72. implemented in mixins. This gives you a better control about the actual
  73. API of your response objects, so you can create subclasses and add custom
  74. functionality. A full featured response object is available as
  75. :class:`Response` which implements a couple of useful mixins.
  76. To enforce a new type of already existing responses you can use the
  77. :meth:`force_type` method. This is useful if you're working with different
  78. subclasses of response objects and you want to post process them with a
  79. known interface.
  80. Per default the response object will assume all the text data is `utf-8`
  81. encoded. Please refer to :doc:`the unicode chapter </unicode>` for more
  82. details about customizing the behavior.
  83. Response can be any kind of iterable or string. If it's a string it's
  84. considered being an iterable with one item which is the string passed.
  85. Headers can be a list of tuples or a
  86. :class:`~werkzeug.datastructures.Headers` object.
  87. Special note for `mimetype` and `content_type`: For most mime types
  88. `mimetype` and `content_type` work the same, the difference affects
  89. only 'text' mimetypes. If the mimetype passed with `mimetype` is a
  90. mimetype starting with `text/`, the charset parameter of the response
  91. object is appended to it. In contrast the `content_type` parameter is
  92. always added as header unmodified.
  93. .. versionchanged:: 0.5
  94. the `direct_passthrough` parameter was added.
  95. :param response: a string or response iterable.
  96. :param status: a string with a status or an integer with the status code.
  97. :param headers: a list of headers or a
  98. :class:`~werkzeug.datastructures.Headers` object.
  99. :param mimetype: the mimetype for the response. See notice above.
  100. :param content_type: the content type for the response. See notice above.
  101. :param direct_passthrough: if set to `True` :meth:`iter_encoded` is not
  102. called before iteration which makes it
  103. possible to pass special iterators through
  104. unchanged (see :func:`wrap_file` for more
  105. details.)
  106. """
  107. #: the charset of the response.
  108. charset = "utf-8"
  109. #: the default status if none is provided.
  110. default_status = 200
  111. #: the default mimetype if none is provided.
  112. default_mimetype = "text/plain"
  113. #: if set to `False` accessing properties on the response object will
  114. #: not try to consume the response iterator and convert it into a list.
  115. #:
  116. #: .. versionadded:: 0.6.2
  117. #:
  118. #: That attribute was previously called `implicit_seqence_conversion`.
  119. #: (Notice the typo). If you did use this feature, you have to adapt
  120. #: your code to the name change.
  121. implicit_sequence_conversion = True
  122. #: Should this response object correct the location header to be RFC
  123. #: conformant? This is true by default.
  124. #:
  125. #: .. versionadded:: 0.8
  126. autocorrect_location_header = True
  127. #: Should this response object automatically set the content-length
  128. #: header if possible? This is true by default.
  129. #:
  130. #: .. versionadded:: 0.8
  131. automatically_set_content_length = True
  132. #: Warn if a cookie header exceeds this size. The default, 4093, should be
  133. #: safely `supported by most browsers <cookie_>`_. A cookie larger than
  134. #: this size will still be sent, but it may be ignored or handled
  135. #: incorrectly by some browsers. Set to 0 to disable this check.
  136. #:
  137. #: .. versionadded:: 0.13
  138. #:
  139. #: .. _`cookie`: http://browsercookielimits.squawky.net/
  140. max_cookie_size = 4093
  141. def __init__(
  142. self,
  143. response=None,
  144. status=None,
  145. headers=None,
  146. mimetype=None,
  147. content_type=None,
  148. direct_passthrough=False,
  149. ):
  150. if isinstance(headers, Headers):
  151. self.headers = headers
  152. elif not headers:
  153. self.headers = Headers()
  154. else:
  155. self.headers = Headers(headers)
  156. if content_type is None:
  157. if mimetype is None and "content-type" not in self.headers:
  158. mimetype = self.default_mimetype
  159. if mimetype is not None:
  160. mimetype = get_content_type(mimetype, self.charset)
  161. content_type = mimetype
  162. if content_type is not None:
  163. self.headers["Content-Type"] = content_type
  164. if status is None:
  165. status = self.default_status
  166. if isinstance(status, integer_types):
  167. self.status_code = status
  168. else:
  169. self.status = status
  170. self.direct_passthrough = direct_passthrough
  171. self._on_close = []
  172. # we set the response after the headers so that if a class changes
  173. # the charset attribute, the data is set in the correct charset.
  174. if response is None:
  175. self.response = []
  176. elif isinstance(response, (text_type, bytes, bytearray)):
  177. self.set_data(response)
  178. else:
  179. self.response = response
  180. def call_on_close(self, func):
  181. """Adds a function to the internal list of functions that should
  182. be called as part of closing down the response. Since 0.7 this
  183. function also returns the function that was passed so that this
  184. can be used as a decorator.
  185. .. versionadded:: 0.6
  186. """
  187. self._on_close.append(func)
  188. return func
  189. def __repr__(self):
  190. if self.is_sequence:
  191. body_info = "%d bytes" % sum(map(len, self.iter_encoded()))
  192. else:
  193. body_info = "streamed" if self.is_streamed else "likely-streamed"
  194. return "<%s %s [%s]>" % (self.__class__.__name__, body_info, self.status)
  195. @classmethod
  196. def force_type(cls, response, environ=None):
  197. """Enforce that the WSGI response is a response object of the current
  198. type. Werkzeug will use the :class:`BaseResponse` internally in many
  199. situations like the exceptions. If you call :meth:`get_response` on an
  200. exception you will get back a regular :class:`BaseResponse` object, even
  201. if you are using a custom subclass.
  202. This method can enforce a given response type, and it will also
  203. convert arbitrary WSGI callables into response objects if an environ
  204. is provided::
  205. # convert a Werkzeug response object into an instance of the
  206. # MyResponseClass subclass.
  207. response = MyResponseClass.force_type(response)
  208. # convert any WSGI application into a response object
  209. response = MyResponseClass.force_type(response, environ)
  210. This is especially useful if you want to post-process responses in
  211. the main dispatcher and use functionality provided by your subclass.
  212. Keep in mind that this will modify response objects in place if
  213. possible!
  214. :param response: a response object or wsgi application.
  215. :param environ: a WSGI environment object.
  216. :return: a response object.
  217. """
  218. if not isinstance(response, BaseResponse):
  219. if environ is None:
  220. raise TypeError(
  221. "cannot convert WSGI application into response"
  222. " objects without an environ"
  223. )
  224. response = BaseResponse(*_run_wsgi_app(response, environ))
  225. response.__class__ = cls
  226. return response
  227. @classmethod
  228. def from_app(cls, app, environ, buffered=False):
  229. """Create a new response object from an application output. This
  230. works best if you pass it an application that returns a generator all
  231. the time. Sometimes applications may use the `write()` callable
  232. returned by the `start_response` function. This tries to resolve such
  233. edge cases automatically. But if you don't get the expected output
  234. you should set `buffered` to `True` which enforces buffering.
  235. :param app: the WSGI application to execute.
  236. :param environ: the WSGI environment to execute against.
  237. :param buffered: set to `True` to enforce buffering.
  238. :return: a response object.
  239. """
  240. return cls(*_run_wsgi_app(app, environ, buffered))
  241. @property
  242. def status_code(self):
  243. """The HTTP status code as a number."""
  244. return self._status_code
  245. @status_code.setter
  246. def status_code(self, code):
  247. self._status_code = code
  248. try:
  249. self._status = "%d %s" % (code, HTTP_STATUS_CODES[code].upper())
  250. except KeyError:
  251. self._status = "%d UNKNOWN" % code
  252. @property
  253. def status(self):
  254. """The HTTP status code as a string."""
  255. return self._status
  256. @status.setter
  257. def status(self, value):
  258. try:
  259. self._status = to_native(value)
  260. except AttributeError:
  261. raise TypeError("Invalid status argument")
  262. try:
  263. self._status_code = int(self._status.split(None, 1)[0])
  264. except ValueError:
  265. self._status_code = 0
  266. self._status = "0 %s" % self._status
  267. except IndexError:
  268. raise ValueError("Empty status argument")
  269. def get_data(self, as_text=False):
  270. """The string representation of the request body. Whenever you call
  271. this property the request iterable is encoded and flattened. This
  272. can lead to unwanted behavior if you stream big data.
  273. This behavior can be disabled by setting
  274. :attr:`implicit_sequence_conversion` to `False`.
  275. If `as_text` is set to `True` the return value will be a decoded
  276. unicode string.
  277. .. versionadded:: 0.9
  278. """
  279. self._ensure_sequence()
  280. rv = b"".join(self.iter_encoded())
  281. if as_text:
  282. rv = rv.decode(self.charset)
  283. return rv
  284. def set_data(self, value):
  285. """Sets a new string as response. The value set must be either a
  286. unicode or bytestring. If a unicode string is set it's encoded
  287. automatically to the charset of the response (utf-8 by default).
  288. .. versionadded:: 0.9
  289. """
  290. # if an unicode string is set, it's encoded directly so that we
  291. # can set the content length
  292. if isinstance(value, text_type):
  293. value = value.encode(self.charset)
  294. else:
  295. value = bytes(value)
  296. self.response = [value]
  297. if self.automatically_set_content_length:
  298. self.headers["Content-Length"] = str(len(value))
  299. data = property(
  300. get_data,
  301. set_data,
  302. doc="A descriptor that calls :meth:`get_data` and :meth:`set_data`.",
  303. )
  304. def calculate_content_length(self):
  305. """Returns the content length if available or `None` otherwise."""
  306. try:
  307. self._ensure_sequence()
  308. except RuntimeError:
  309. return None
  310. return sum(len(x) for x in self.iter_encoded())
  311. def _ensure_sequence(self, mutable=False):
  312. """This method can be called by methods that need a sequence. If
  313. `mutable` is true, it will also ensure that the response sequence
  314. is a standard Python list.
  315. .. versionadded:: 0.6
  316. """
  317. if self.is_sequence:
  318. # if we need a mutable object, we ensure it's a list.
  319. if mutable and not isinstance(self.response, list):
  320. self.response = list(self.response)
  321. return
  322. if self.direct_passthrough:
  323. raise RuntimeError(
  324. "Attempted implicit sequence conversion but the"
  325. " response object is in direct passthrough mode."
  326. )
  327. if not self.implicit_sequence_conversion:
  328. raise RuntimeError(
  329. "The response object required the iterable to be a"
  330. " sequence, but the implicit conversion was disabled."
  331. " Call make_sequence() yourself."
  332. )
  333. self.make_sequence()
  334. def make_sequence(self):
  335. """Converts the response iterator in a list. By default this happens
  336. automatically if required. If `implicit_sequence_conversion` is
  337. disabled, this method is not automatically called and some properties
  338. might raise exceptions. This also encodes all the items.
  339. .. versionadded:: 0.6
  340. """
  341. if not self.is_sequence:
  342. # if we consume an iterable we have to ensure that the close
  343. # method of the iterable is called if available when we tear
  344. # down the response
  345. close = getattr(self.response, "close", None)
  346. self.response = list(self.iter_encoded())
  347. if close is not None:
  348. self.call_on_close(close)
  349. def iter_encoded(self):
  350. """Iter the response encoded with the encoding of the response.
  351. If the response object is invoked as WSGI application the return
  352. value of this method is used as application iterator unless
  353. :attr:`direct_passthrough` was activated.
  354. """
  355. if __debug__:
  356. _warn_if_string(self.response)
  357. # Encode in a separate function so that self.response is fetched
  358. # early. This allows us to wrap the response with the return
  359. # value from get_app_iter or iter_encoded.
  360. return _iter_encoded(self.response, self.charset)
  361. def set_cookie(
  362. self,
  363. key,
  364. value="",
  365. max_age=None,
  366. expires=None,
  367. path="/",
  368. domain=None,
  369. secure=False,
  370. httponly=False,
  371. samesite=None,
  372. ):
  373. """Sets a cookie. The parameters are the same as in the cookie `Morsel`
  374. object in the Python standard library but it accepts unicode data, too.
  375. A warning is raised if the size of the cookie header exceeds
  376. :attr:`max_cookie_size`, but the header will still be set.
  377. :param key: the key (name) of the cookie to be set.
  378. :param value: the value of the cookie.
  379. :param max_age: should be a number of seconds, or `None` (default) if
  380. the cookie should last only as long as the client's
  381. browser session.
  382. :param expires: should be a `datetime` object or UNIX timestamp.
  383. :param path: limits the cookie to a given path, per default it will
  384. span the whole domain.
  385. :param domain: if you want to set a cross-domain cookie. For example,
  386. ``domain=".example.com"`` will set a cookie that is
  387. readable by the domain ``www.example.com``,
  388. ``foo.example.com`` etc. Otherwise, a cookie will only
  389. be readable by the domain that set it.
  390. :param secure: If `True`, the cookie will only be available via HTTPS
  391. :param httponly: disallow JavaScript to access the cookie. This is an
  392. extension to the cookie standard and probably not
  393. supported by all browsers.
  394. :param samesite: Limits the scope of the cookie such that it will only
  395. be attached to requests if those requests are
  396. "same-site".
  397. """
  398. self.headers.add(
  399. "Set-Cookie",
  400. dump_cookie(
  401. key,
  402. value=value,
  403. max_age=max_age,
  404. expires=expires,
  405. path=path,
  406. domain=domain,
  407. secure=secure,
  408. httponly=httponly,
  409. charset=self.charset,
  410. max_size=self.max_cookie_size,
  411. samesite=samesite,
  412. ),
  413. )
  414. def delete_cookie(self, key, path="/", domain=None):
  415. """Delete a cookie. Fails silently if key doesn't exist.
  416. :param key: the key (name) of the cookie to be deleted.
  417. :param path: if the cookie that should be deleted was limited to a
  418. path, the path has to be defined here.
  419. :param domain: if the cookie that should be deleted was limited to a
  420. domain, that domain has to be defined here.
  421. """
  422. self.set_cookie(key, expires=0, max_age=0, path=path, domain=domain)
  423. @property
  424. def is_streamed(self):
  425. """If the response is streamed (the response is not an iterable with
  426. a length information) this property is `True`. In this case streamed
  427. means that there is no information about the number of iterations.
  428. This is usually `True` if a generator is passed to the response object.
  429. This is useful for checking before applying some sort of post
  430. filtering that should not take place for streamed responses.
  431. """
  432. try:
  433. len(self.response)
  434. except (TypeError, AttributeError):
  435. return True
  436. return False
  437. @property
  438. def is_sequence(self):
  439. """If the iterator is buffered, this property will be `True`. A
  440. response object will consider an iterator to be buffered if the
  441. response attribute is a list or tuple.
  442. .. versionadded:: 0.6
  443. """
  444. return isinstance(self.response, (tuple, list))
  445. def close(self):
  446. """Close the wrapped response if possible. You can also use the object
  447. in a with statement which will automatically close it.
  448. .. versionadded:: 0.9
  449. Can now be used in a with statement.
  450. """
  451. if hasattr(self.response, "close"):
  452. self.response.close()
  453. for func in self._on_close:
  454. func()
  455. def __enter__(self):
  456. return self
  457. def __exit__(self, exc_type, exc_value, tb):
  458. self.close()
  459. def freeze(self):
  460. """Call this method if you want to make your response object ready for
  461. being pickled. This buffers the generator if there is one. It will
  462. also set the `Content-Length` header to the length of the body.
  463. .. versionchanged:: 0.6
  464. The `Content-Length` header is now set.
  465. """
  466. # we explicitly set the length to a list of the *encoded* response
  467. # iterator. Even if the implicit sequence conversion is disabled.
  468. self.response = list(self.iter_encoded())
  469. self.headers["Content-Length"] = str(sum(map(len, self.response)))
  470. def get_wsgi_headers(self, environ):
  471. """This is automatically called right before the response is started
  472. and returns headers modified for the given environment. It returns a
  473. copy of the headers from the response with some modifications applied
  474. if necessary.
  475. For example the location header (if present) is joined with the root
  476. URL of the environment. Also the content length is automatically set
  477. to zero here for certain status codes.
  478. .. versionchanged:: 0.6
  479. Previously that function was called `fix_headers` and modified
  480. the response object in place. Also since 0.6, IRIs in location
  481. and content-location headers are handled properly.
  482. Also starting with 0.6, Werkzeug will attempt to set the content
  483. length if it is able to figure it out on its own. This is the
  484. case if all the strings in the response iterable are already
  485. encoded and the iterable is buffered.
  486. :param environ: the WSGI environment of the request.
  487. :return: returns a new :class:`~werkzeug.datastructures.Headers`
  488. object.
  489. """
  490. headers = Headers(self.headers)
  491. location = None
  492. content_location = None
  493. content_length = None
  494. status = self.status_code
  495. # iterate over the headers to find all values in one go. Because
  496. # get_wsgi_headers is used each response that gives us a tiny
  497. # speedup.
  498. for key, value in headers:
  499. ikey = key.lower()
  500. if ikey == u"location":
  501. location = value
  502. elif ikey == u"content-location":
  503. content_location = value
  504. elif ikey == u"content-length":
  505. content_length = value
  506. # make sure the location header is an absolute URL
  507. if location is not None:
  508. old_location = location
  509. if isinstance(location, text_type):
  510. # Safe conversion is necessary here as we might redirect
  511. # to a broken URI scheme (for instance itms-services).
  512. location = iri_to_uri(location, safe_conversion=True)
  513. if self.autocorrect_location_header:
  514. current_url = get_current_url(environ, strip_querystring=True)
  515. if isinstance(current_url, text_type):
  516. current_url = iri_to_uri(current_url)
  517. location = url_join(current_url, location)
  518. if location != old_location:
  519. headers["Location"] = location
  520. # make sure the content location is a URL
  521. if content_location is not None and isinstance(content_location, text_type):
  522. headers["Content-Location"] = iri_to_uri(content_location)
  523. if 100 <= status < 200 or status == 204:
  524. # Per section 3.3.2 of RFC 7230, "a server MUST NOT send a
  525. # Content-Length header field in any response with a status
  526. # code of 1xx (Informational) or 204 (No Content)."
  527. headers.remove("Content-Length")
  528. elif status == 304:
  529. remove_entity_headers(headers)
  530. # if we can determine the content length automatically, we
  531. # should try to do that. But only if this does not involve
  532. # flattening the iterator or encoding of unicode strings in
  533. # the response. We however should not do that if we have a 304
  534. # response.
  535. if (
  536. self.automatically_set_content_length
  537. and self.is_sequence
  538. and content_length is None
  539. and status not in (204, 304)
  540. and not (100 <= status < 200)
  541. ):
  542. try:
  543. content_length = sum(len(to_bytes(x, "ascii")) for x in self.response)
  544. except UnicodeError:
  545. # aha, something non-bytestringy in there, too bad, we
  546. # can't safely figure out the length of the response.
  547. pass
  548. else:
  549. headers["Content-Length"] = str(content_length)
  550. return headers
  551. def get_app_iter(self, environ):
  552. """Returns the application iterator for the given environ. Depending
  553. on the request method and the current status code the return value
  554. might be an empty response rather than the one from the response.
  555. If the request method is `HEAD` or the status code is in a range
  556. where the HTTP specification requires an empty response, an empty
  557. iterable is returned.
  558. .. versionadded:: 0.6
  559. :param environ: the WSGI environment of the request.
  560. :return: a response iterable.
  561. """
  562. status = self.status_code
  563. if (
  564. environ["REQUEST_METHOD"] == "HEAD"
  565. or 100 <= status < 200
  566. or status in (204, 304)
  567. ):
  568. iterable = ()
  569. elif self.direct_passthrough:
  570. if __debug__:
  571. _warn_if_string(self.response)
  572. return self.response
  573. else:
  574. iterable = self.iter_encoded()
  575. return ClosingIterator(iterable, self.close)
  576. def get_wsgi_response(self, environ):
  577. """Returns the final WSGI response as tuple. The first item in
  578. the tuple is the application iterator, the second the status and
  579. the third the list of headers. The response returned is created
  580. specially for the given environment. For example if the request
  581. method in the WSGI environment is ``'HEAD'`` the response will
  582. be empty and only the headers and status code will be present.
  583. .. versionadded:: 0.6
  584. :param environ: the WSGI environment of the request.
  585. :return: an ``(app_iter, status, headers)`` tuple.
  586. """
  587. headers = self.get_wsgi_headers(environ)
  588. app_iter = self.get_app_iter(environ)
  589. return app_iter, self.status, headers.to_wsgi_list()
  590. def __call__(self, environ, start_response):
  591. """Process this response as WSGI application.
  592. :param environ: the WSGI environment.
  593. :param start_response: the response callable provided by the WSGI
  594. server.
  595. :return: an application iterator
  596. """
  597. app_iter, status, headers = self.get_wsgi_response(environ)
  598. start_response(status, headers)
  599. return app_iter