Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding a warning response header for deprecated apis. #498

Merged
merged 1 commit into from
Aug 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading