{"action":"created","comment":{"url":"https://api.github.com/repos/django/django/pulls/comments/63061509","id":63061509,"diff_hunk":"@@ -16,18 +16,128 @@ how to write your own middleware. Django ships with some built-in middleware\n you can use right out of the box. They're documented in the :doc:`built-in\n middleware reference </ref/middleware>`.\n \n+.. versionchanged:: 1.10\n+\n+    A new style of middleware was introduced for use with the new\n+    :setting:`MIDDLEWARE` setting. If you're using the old\n+    :setting:`MIDDLEWARE_CLASSES` setting, you'll need to :ref:`adapt old,\n+    custom middleware <upgrading-middleware>` before using the new setting.\n+    This document describes new-style middleware. Refer to this page in older\n+    versions of the documentation for a description of how old-style middleware\n+    works.\n+\n+Writing your own middleware\n+===========================\n+\n+A middleware factory is a callable that takes a ``get_response`` callable and\n+returns a middleware. A middleware is a callable that takes a request and\n+returns a response, just like a view.\n+\n+A middleware can be written as a function that looks like this::\n+\n+    def simple_middleware(get_response):\n+        # One-time configuration and initialization.\n+\n+        def middleware(request):\n+            # Code to be executed for each request before\n+            # the view is called.\n+\n+            try:\n+                response = get_response(request)\n+            except Exception as e:\n+                # Code to handle an exception that wasn't caught\n+                # further up the chain, if desired.\n+                ...\n+\n+            # Code to be executed for each request/response after\n+            # the view is called.\n+\n+            return response\n+\n+        return middleware\n+\n+Or it can be written as a class with a ``__call__()`` method, like this::\n+\n+    class SimpleMiddleware(object):\n+        def __init__(self, get_response):\n+            self.get_response = get_response\n+            # One-time configuration and initialization.\n+\n+        def __call__(self, request):\n+            # Code to be executed for each request before\n+            # the view is called.\n+\n+            try:\n+                response = self. get_response(request)","path":"docs/topics/http/middleware.txt","position":56,"original_position":56,"commit_id":"907e62e4b30a760f0a80cf2f3eb3299ee02ed7e0","original_commit_id":"907e62e4b30a760f0a80cf2f3eb3299ee02ed7e0","user":{"login":"carljm","id":61586,"avatar_url":"https://avatars.githubusercontent.com/u/61586?v=3","gravatar_id":"","url":"https://api.github.com/users/carljm","html_url":"https://github.com/carljm","followers_url":"https://api.github.com/users/carljm/followers","following_url":"https://api.github.com/users/carljm/following{/other_user}","gists_url":"https://api.github.com/users/carljm/gists{/gist_id}","starred_url":"https://api.github.com/users/carljm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/carljm/subscriptions","organizations_url":"https://api.github.com/users/carljm/orgs","repos_url":"https://api.github.com/users/carljm/repos","events_url":"https://api.github.com/users/carljm/events{/privacy}","received_events_url":"https://api.github.com/users/carljm/received_events","type":"User","site_admin":false},"body":"Extra space after the period in this line","created_at":"2016-05-12T17:26:41Z","updated_at":"2016-05-12T17:26:41Z","html_url":"https://github.com/django/django/pull/6501#discussion_r63061509","pull_request_url":"https://api.github.com/repos/django/django/pulls/6501","_links":{"self":{"href":"https://api.github.com/repos/django/django/pulls/comments/63061509"},"html":{"href":"https://github.com/django/django/pull/6501#discussion_r63061509"},"pull_request":{"href":"https://api.github.com/repos/django/django/pulls/6501"}}},"pull_request":{"url":"https://api.github.com/repos/django/django/pulls/6501","id":67622036,"html_url":"https://github.com/django/django/pull/6501","diff_url":"https://github.com/django/django/pull/6501.diff","patch_url":"https://github.com/django/django/pull/6501.patch","issue_url":"https://api.github.com/repos/django/django/issues/6501","number":6501,"state":"open","locked":false,"title":"Fixed #26601 -- Improved middleware per DEP 0005.","user":{"login":"timgraham","id":411869,"avatar_url":"https://avatars.githubusercontent.com/u/411869?v=3","gravatar_id":"","url":"https://api.github.com/users/timgraham","html_url":"https://github.com/timgraham","followers_url":"https://api.github.com/users/timgraham/followers","following_url":"https://api.github.com/users/timgraham/following{/other_user}","gists_url":"https://api.github.com/users/timgraham/gists{/gist_id}","starred_url":"https://api.github.com/users/timgraham/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/timgraham/subscriptions","organizations_url":"https://api.github.com/users/timgraham/orgs","repos_url":"https://api.github.com/users/timgraham/repos","events_url":"https://api.github.com/users/timgraham/events{/privacy}","received_events_url":"https://api.github.com/users/timgraham/received_events","type":"User","site_admin":false},"body":"Rebased from https://github.com/django/django/pull/6371. A minimal viable patch for merge.\r\n\r\nTo be ticketed out for future enhancements:\r\n* update `decorator_from_middleware` (if needed)\r\n* provide a new documentation graphic for how middleware works (if needed, not quite sure what it would look like)\r\n\r\nUnlike what the DEP suggest, I don't see a need to immediately deprecate `MiddlewareMixin`. I'd be fine considering a deprecation in Django 2.0 or so but I don't see a need to rush it? An immediate deprecation wouldn't allow writing middleware that uses it without having to silence warnings.'","created_at":"2016-04-23T23:31:46Z","updated_at":"2016-05-12T17:26:41Z","closed_at":null,"merged_at":null,"merge_commit_sha":"89251cc1c9b553b7c4386d2e8433f2a51b6132f7","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/django/django/pulls/6501/commits","review_comments_url":"https://api.github.com/repos/django/django/pulls/6501/comments","review_comment_url":"https://api.github.com/repos/django/django/pulls/comments{/number}","comments_url":"https://api.github.com/repos/django/django/issues/6501/comments","statuses_url":"https://api.github.com/repos/django/django/statuses/907e62e4b30a760f0a80cf2f3eb3299ee02ed7e0","head":{"label":"django:dep5","ref":"dep5","sha":"907e62e4b30a760f0a80cf2f3eb3299ee02ed7e0","user":{"login":"django","id":27804,"avatar_url":"https://avatars.githubusercontent.com/u/27804?v=3","gravatar_id":"","url":"https://api.github.com/users/django","html_url":"https://github.com/django","followers_url":"https://api.github.com/users/django/followers","following_url":"https://api.github.com/users/django/following{/other_user}","gists_url":"https://api.github.com/users/django/gists{/gist_id}","starred_url":"https://api.github.com/users/django/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/django/subscriptions","organizations_url":"https://api.github.com/users/django/orgs","repos_url":"https://api.github.com/users/django/repos","events_url":"https://api.github.com/users/django/events{/privacy}","received_events_url":"https://api.github.com/users/django/received_events","type":"Organization","site_admin":false},"repo":{"id":4164482,"name":"django","full_name":"django/django","owner":{"login":"django","id":27804,"avatar_url":"https://avatars.githubusercontent.com/u/27804?v=3","gravatar_id":"","url":"https://api.github.com/users/django","html_url":"https://github.com/django","followers_url":"https://api.github.com/users/django/followers","following_url":"https://api.github.com/users/django/following{/other_user}","gists_url":"https://api.github.com/users/django/gists{/gist_id}","starred_url":"https://api.github.com/users/django/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/django/subscriptions","organizations_url":"https://api.github.com/users/django/orgs","repos_url":"https://api.github.com/users/django/repos","events_url":"https://api.github.com/users/django/events{/privacy}","received_events_url":"https://api.github.com/users/django/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/django/django","description":"The Web framework for perfectionists with deadlines.","fork":false,"url":"https://api.github.com/repos/django/django","forks_url":"https://api.github.com/repos/django/django/forks","keys_url":"https://api.github.com/repos/django/django/keys{/key_id}","collaborators_url":"https://api.github.com/repos/django/django/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/django/django/teams","hooks_url":"https://api.github.com/repos/django/django/hooks","issue_events_url":"https://api.github.com/repos/django/django/issues/events{/number}","events_url":"https://api.github.com/repos/django/django/events","assignees_url":"https://api.github.com/repos/django/django/assignees{/user}","branches_url":"https://api.github.com/repos/django/django/branches{/branch}","tags_url":"https://api.github.com/repos/django/django/tags","blobs_url":"https://api.github.com/repos/django/django/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/django/django/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/django/django/git/refs{/sha}","trees_url":"https://api.github.com/repos/django/django/git/trees{/sha}","statuses_url":"https://api.github.com/repos/django/django/statuses/{sha}","languages_url":"https://api.github.com/repos/django/django/languages","stargazers_url":"https://api.github.com/repos/django/django/stargazers","contributors_url":"https://api.github.com/repos/django/django/contributors","subscribers_url":"https://api.github.com/repos/django/django/subscribers","subscription_url":"https://api.github.com/repos/django/django/subscription","commits_url":"https://api.github.com/repos/django/django/commits{/sha}","git_commits_url":"https://api.github.com/repos/django/django/git/commits{/sha}","comments_url":"https://api.github.com/repos/django/django/comments{/number}","issue_comment_url":"https://api.github.com/repos/django/django/issues/comments{/number}","contents_url":"https://api.github.com/repos/django/django/contents/{+path}","compare_url":"https://api.github.com/repos/django/django/compare/{base}...{head}","merges_url":"https://api.github.com/repos/django/django/merges","archive_url":"https://api.github.com/repos/django/django/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/django/django/downloads","issues_url":"https://api.github.com/repos/django/django/issues{/number}","pulls_url":"https://api.github.com/repos/django/django/pulls{/number}","milestones_url":"https://api.github.com/repos/django/django/milestones{/number}","notifications_url":"https://api.github.com/repos/django/django/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/django/django/labels{/name}","releases_url":"https://api.github.com/repos/django/django/releases{/id}","deployments_url":"https://api.github.com/repos/django/django/deployments","created_at":"2012-04-28T02:47:18Z","updated_at":"2016-05-12T17:21:06Z","pushed_at":"2016-05-12T17:12:30Z","git_url":"git://github.com/django/django.git","ssh_url":"git@github.com:django/django.git","clone_url":"https://github.com/django/django.git","svn_url":"https://github.com/django/django","homepage":"https://www.djangoproject.com/","size":192610,"stargazers_count":19382,"watchers_count":19382,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":7817,"mirror_url":null,"open_issues_count":80,"forks":7817,"open_issues":80,"watchers":19382,"default_branch":"master"}},"base":{"label":"django:master","ref":"master","sha":"069319396f0e9fb10254e1bcf578336392c9cffb","user":{"login":"django","id":27804,"avatar_url":"https://avatars.githubusercontent.com/u/27804?v=3","gravatar_id":"","url":"https://api.github.com/users/django","html_url":"https://github.com/django","followers_url":"https://api.github.com/users/django/followers","following_url":"https://api.github.com/users/django/following{/other_user}","gists_url":"https://api.github.com/users/django/gists{/gist_id}","starred_url":"https://api.github.com/users/django/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/django/subscriptions","organizations_url":"https://api.github.com/users/django/orgs","repos_url":"https://api.github.com/users/django/repos","events_url":"https://api.github.com/users/django/events{/privacy}","received_events_url":"https://api.github.com/users/django/received_events","type":"Organization","site_admin":false},"repo":{"id":4164482,"name":"django","full_name":"django/django","owner":{"login":"django","id":27804,"avatar_url":"https://avatars.githubusercontent.com/u/27804?v=3","gravatar_id":"","url":"https://api.github.com/users/django","html_url":"https://github.com/django","followers_url":"https://api.github.com/users/django/followers","following_url":"https://api.github.com/users/django/following{/other_user}","gists_url":"https://api.github.com/users/django/gists{/gist_id}","starred_url":"https://api.github.com/users/django/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/django/subscriptions","organizations_url":"https://api.github.com/users/django/orgs","repos_url":"https://api.github.com/users/django/repos","events_url":"https://api.github.com/users/django/events{/privacy}","received_events_url":"https://api.github.com/users/django/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/django/django","description":"The Web framework for perfectionists with deadlines.","fork":false,"url":"https://api.github.com/repos/django/django","forks_url":"https://api.github.com/repos/django/django/forks","keys_url":"https://api.github.com/repos/django/django/keys{/key_id}","collaborators_url":"https://api.github.com/repos/django/django/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/django/django/teams","hooks_url":"https://api.github.com/repos/django/django/hooks","issue_events_url":"https://api.github.com/repos/django/django/issues/events{/number}","events_url":"https://api.github.com/repos/django/django/events","assignees_url":"https://api.github.com/repos/django/django/assignees{/user}","branches_url":"https://api.github.com/repos/django/django/branches{/branch}","tags_url":"https://api.github.com/repos/django/django/tags","blobs_url":"https://api.github.com/repos/django/django/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/django/django/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/django/django/git/refs{/sha}","trees_url":"https://api.github.com/repos/django/django/git/trees{/sha}","statuses_url":"https://api.github.com/repos/django/django/statuses/{sha}","languages_url":"https://api.github.com/repos/django/django/languages","stargazers_url":"https://api.github.com/repos/django/django/stargazers","contributors_url":"https://api.github.com/repos/django/django/contributors","subscribers_url":"https://api.github.com/repos/django/django/subscribers","subscription_url":"https://api.github.com/repos/django/django/subscription","commits_url":"https://api.github.com/repos/django/django/commits{/sha}","git_commits_url":"https://api.github.com/repos/django/django/git/commits{/sha}","comments_url":"https://api.github.com/repos/django/django/comments{/number}","issue_comment_url":"https://api.github.com/repos/django/django/issues/comments{/number}","contents_url":"https://api.github.com/repos/django/django/contents/{+path}","compare_url":"https://api.github.com/repos/django/django/compare/{base}...{head}","merges_url":"https://api.github.com/repos/django/django/merges","archive_url":"https://api.github.com/repos/django/django/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/django/django/downloads","issues_url":"https://api.github.com/repos/django/django/issues{/number}","pulls_url":"https://api.github.com/repos/django/django/pulls{/number}","milestones_url":"https://api.github.com/repos/django/django/milestones{/number}","notifications_url":"https://api.github.com/repos/django/django/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/django/django/labels{/name}","releases_url":"https://api.github.com/repos/django/django/releases{/id}","deployments_url":"https://api.github.com/repos/django/django/deployments","created_at":"2012-04-28T02:47:18Z","updated_at":"2016-05-12T17:21:06Z","pushed_at":"2016-05-12T17:12:30Z","git_url":"git://github.com/django/django.git","ssh_url":"git@github.com:django/django.git","clone_url":"https://github.com/django/django.git","svn_url":"https://github.com/django/django","homepage":"https://www.djangoproject.com/","size":192610,"stargazers_count":19382,"watchers_count":19382,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":7817,"mirror_url":null,"open_issues_count":80,"forks":7817,"open_issues":80,"watchers":19382,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/django/django/pulls/6501"},"html":{"href":"https://github.com/django/django/pull/6501"},"issue":{"href":"https://api.github.com/repos/django/django/issues/6501"},"comments":{"href":"https://api.github.com/repos/django/django/issues/6501/comments"},"review_comments":{"href":"https://api.github.com/repos/django/django/pulls/6501/comments"},"review_comment":{"href":"https://api.github.com/repos/django/django/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/django/django/pulls/6501/commits"},"statuses":{"href":"https://api.github.com/repos/django/django/statuses/907e62e4b30a760f0a80cf2f3eb3299ee02ed7e0"}}}}