Skip to content

Commit

Permalink
Merge pull request #498 from open5e/489-v1v2-betadeprecation-headers
Browse files Browse the repository at this point in the history
Adding a warning response header for deprecated apis.
  • Loading branch information
augustjohnson authored Aug 4, 2024
2 parents 933fb82 + a8f3e21 commit 514d2ee
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
16 changes: 16 additions & 0 deletions server/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,20 @@ def __call__(self, request):

response = self.get_response(request)

return response

class ResponseWarningHeaderMiddleware:
def __init__(self, get_response):
self.get_response = get_response

def __call__(self, request):
response = self.get_response(request)
if request.path.startswith('/v1'):
response_message = "299 Deprecated API: use /v2/ instead. /v1/ will be maintained until 2024-12-31."

if request.path in ['/v1/search','/v1/search/']:
response_message = "299 Deprecated API: use /v2/search instead."

response.headers['Warning'] = response_message

return response
1 change: 1 addition & 0 deletions server/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
"server.middleware.NewRelicMiddleware",
"server.middleware.ResponseWarningHeaderMiddleware"
]

HAYSTACK_CONNECTIONS = {
Expand Down

0 comments on commit 514d2ee

Please sign in to comment.