We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
link to profile breaks if space in username


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `apps/embed/middleware.py`
Content:
```
1 class AjaxPathMiddleware(object):
2     """Append request path as a header.
3 
4     In an ajax request, redirects are handled implicitly, so it it not possible
5     to know the path of the page where you end up. This middleware adds that
6     information in a header.
7     """
8 
9     def process_response(self, request, response):
10         response['x-ajax-path'] = request.path
11         return response
12
```
--- 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()

```

diff --git a/apps/embed/middleware.py b/apps/embed/middleware.py
--- a/apps/embed/middleware.py
+++ b/apps/embed/middleware.py
@@ -1,3 +1,6 @@
+from django.utils.http import urlquote
+
+
 class AjaxPathMiddleware(object):
     """Append request path as a header.
 
@@ -7,5 +10,5 @@
     """
 
     def process_response(self, request, response):
-        response['x-ajax-path'] = request.path
+        response['x-ajax-path'] = urlquote(request.path)
         return response

{"golden_diff": "diff --git a/apps/embed/middleware.py b/apps/embed/middleware.py\n--- a/apps/embed/middleware.py\n+++ b/apps/embed/middleware.py\n@@ -1,3 +1,6 @@\n+from django.utils.http import urlquote\n+\n+\n class AjaxPathMiddleware(object):\n     \"\"\"Append request path as a header.\n \n@@ -7,5 +10,5 @@\n     \"\"\"\n \n     def process_response(self, request, response):\n-        response['x-ajax-path'] = request.path\n+        response['x-ajax-path'] = urlquote(request.path)\n         return response\n", "issue": "link to profile breaks if space in username\n\n", "before_files": [{"content": "class AjaxPathMiddleware(object):\n    \"\"\"Append request path as a header.\n\n    In an ajax request, redirects are handled implicitly, so it it not possible\n    to know the path of the page where you end up. This middleware adds that\n    information in a header.\n    \"\"\"\n\n    def process_response(self, request, response):\n        response['x-ajax-path'] = request.path\n        return response\n", "path": "apps/embed/middleware.py"}], "after_files": [{"content": "from django.utils.http import urlquote\n\n\nclass AjaxPathMiddleware(object):\n    \"\"\"Append request path as a header.\n\n    In an ajax request, redirects are handled implicitly, so it it not possible\n    to know the path of the page where you end up. This middleware adds that\n    information in a header.\n    \"\"\"\n\n    def process_response(self, request, response):\n        response['x-ajax-path'] = urlquote(request.path)\n        return response\n", "path": "apps/embed/middleware.py"}]}