02-backport-is_xhr.patch 1.4 KB

12345678910111213141516171819202122232425262728293031
  1. --- contrib/python/Werkzeug/py3/werkzeug/sansio/request.py (index)
  2. +++ contrib/python/Werkzeug/py3/werkzeug/sansio/request.py (working tree)
  3. @@ -204,6 +204,28 @@ class Request:
  4. return f"{self.path}?{_to_str(self.query_string, self.url_charset)}"
  5. @property
  6. + def is_xhr(self):
  7. + """True if the request was triggered via a JavaScript XMLHttpRequest.
  8. + This only works with libraries that support the ``X-Requested-With``
  9. + header and set it to "XMLHttpRequest". Libraries that do that are
  10. + prototype, jQuery and Mochikit and probably some more.
  11. + .. deprecated:: 0.13
  12. + ``X-Requested-With`` is not standard and is unreliable. You
  13. + may be able to use :attr:`AcceptMixin.accept_mimetypes`
  14. + instead.
  15. + """
  16. + import warnings
  17. + warnings.warn(
  18. + "'Request.is_xhr' is deprecated as of version 0.13 and will"
  19. + " be removed in version 1.0. The 'X-Requested-With' header"
  20. + " is not standard and is unreliable. You may be able to use"
  21. + " 'accept_mimetypes' instead.",
  22. + DeprecationWarning,
  23. + stacklevel=2,
  24. + )
  25. + return self.environ.get("HTTP_X_REQUESTED_WITH", "").lower() == "xmlhttprequest"
  26. +
  27. + @property
  28. def is_secure(self) -> bool:
  29. """``True`` if the request was made with a secure protocol
  30. (HTTPS or WSS).