prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Localhost filter should consider affected URL
  Right now the "localhost" filter only consider's the affected User's IP: https://github.com/getsentry/sentry/blob/master/src/sentry/filters/localhost.py
  
  But users are also expecting that this should filter server errors triggered from a server running on localhost (e.g. local development).
  
  See also: #4729, #4762
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `src/sentry/filters/localhost.py`
  Content:
  ```
  1 from __future__ import absolute_import
  2 
  3 from .base import Filter
  4 
  5 LOCAL_IPS = frozenset(['127.0.0.1', '::1'])
  6 
  7 
  8 class LocalhostFilter(Filter):
  9     id = 'localhost'
  10     name = 'Filter out errors coming from localhost'
  11     description = 'This applies to to both IPv4 (``127.0.0.1``) and IPv6 (``::1``) addresses.'
  12 
  13     def get_ip_address(self, data):
  14         try:
  15             return data['sentry.interfaces.User']['ip_address']
  16         except KeyError:
  17             return ''
  18 
  19     def test(self, data):
  20         return self.get_ip_address(data) in LOCAL_IPS
  21
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/src/sentry/filters/localhost.py b/src/sentry/filters/localhost.py
  --- a/src/sentry/filters/localhost.py
  +++ b/src/sentry/filters/localhost.py
  @@ -1,8 +1,10 @@
   from __future__ import absolute_import
   
   from .base import Filter
  +from six.moves.urllib.parse import urlparse
   
   LOCAL_IPS = frozenset(['127.0.0.1', '::1'])
  +LOCAL_DOMAINS = frozenset(['127.0.0.1', 'localhost'])
   
   
   class LocalhostFilter(Filter):
  @@ -16,5 +18,14 @@
           except KeyError:
               return ''
   
  +    def get_url(self, data):
  +        try:
  +            return data['sentry.interfaces.Http']['url'] or ''
  +        except KeyError:
  +            return ''
  +
  +    def get_domain(self, data):
  +        return urlparse(self.get_url(data)).netloc
  +
       def test(self, data):
  -        return self.get_ip_address(data) in LOCAL_IPS
  +        return self.get_ip_address(data) in LOCAL_IPS or self.get_domain(data) in LOCAL_DOMAINS
  
verification_info: {"golden_diff": "diff --git a/src/sentry/filters/localhost.py b/src/sentry/filters/localhost.py\n--- a/src/sentry/filters/localhost.py\n+++ b/src/sentry/filters/localhost.py\n@@ -1,8 +1,10 @@\n from __future__ import absolute_import\n \n from .base import Filter\n+from six.moves.urllib.parse import urlparse\n \n LOCAL_IPS = frozenset(['127.0.0.1', '::1'])\n+LOCAL_DOMAINS = frozenset(['127.0.0.1', 'localhost'])\n \n \n class LocalhostFilter(Filter):\n@@ -16,5 +18,14 @@\n         except KeyError:\n             return ''\n \n+    def get_url(self, data):\n+        try:\n+            return data['sentry.interfaces.Http']['url'] or ''\n+        except KeyError:\n+            return ''\n+\n+    def get_domain(self, data):\n+        return urlparse(self.get_url(data)).netloc\n+\n     def test(self, data):\n-        return self.get_ip_address(data) in LOCAL_IPS\n+        return self.get_ip_address(data) in LOCAL_IPS or self.get_domain(data) in LOCAL_DOMAINS\n", "issue": "Localhost filter should consider affected URL\nRight now the \"localhost\" filter only consider's the affected User's IP: https://github.com/getsentry/sentry/blob/master/src/sentry/filters/localhost.py\r\n\r\nBut users are also expecting that this should filter server errors triggered from a server running on localhost (e.g. local development).\r\n\r\nSee also: #4729, #4762\n", "before_files": [{"content": "from __future__ import absolute_import\n\nfrom .base import Filter\n\nLOCAL_IPS = frozenset(['127.0.0.1', '::1'])\n\n\nclass LocalhostFilter(Filter):\n    id = 'localhost'\n    name = 'Filter out errors coming from localhost'\n    description = 'This applies to to both IPv4 (``127.0.0.1``) and IPv6 (``::1``) addresses.'\n\n    def get_ip_address(self, data):\n        try:\n            return data['sentry.interfaces.User']['ip_address']\n        except KeyError:\n            return ''\n\n    def test(self, data):\n        return self.get_ip_address(data) in LOCAL_IPS\n", "path": "src/sentry/filters/localhost.py"}], "after_files": [{"content": "from __future__ import absolute_import\n\nfrom .base import Filter\nfrom six.moves.urllib.parse import urlparse\n\nLOCAL_IPS = frozenset(['127.0.0.1', '::1'])\nLOCAL_DOMAINS = frozenset(['127.0.0.1', 'localhost'])\n\n\nclass LocalhostFilter(Filter):\n    id = 'localhost'\n    name = 'Filter out errors coming from localhost'\n    description = 'This applies to to both IPv4 (``127.0.0.1``) and IPv6 (``::1``) addresses.'\n\n    def get_ip_address(self, data):\n        try:\n            return data['sentry.interfaces.User']['ip_address']\n        except KeyError:\n            return ''\n\n    def get_url(self, data):\n        try:\n            return data['sentry.interfaces.Http']['url'] or ''\n        except KeyError:\n            return ''\n\n    def get_domain(self, data):\n        return urlparse(self.get_url(data)).netloc\n\n    def test(self, data):\n        return self.get_ip_address(data) in LOCAL_IPS or self.get_domain(data) in LOCAL_DOMAINS\n", "path": "src/sentry/filters/localhost.py"}]}