-
Notifications
You must be signed in to change notification settings - Fork 214
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add middleware to log application name and verification status (#3369)
* Add middleware to log application name and verification status Also add authorization, app name and verified status to nginx logs * Use clearer name for new middlware
- Loading branch information
1 parent
f56ad17
commit 520d4d9
Showing
7 changed files
with
123 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from api.utils.oauth2_helper import get_token_info | ||
|
||
|
||
def response_headers_middleware(get_response): | ||
""" | ||
Add standard response headers used by Nginx logging. | ||
These headers help Openverse more easily and directly connect | ||
individual requests to each other. This is particularly useful | ||
when evaluating traffic patterns from individual source IPs | ||
to identify malicious requesters or request patterns. | ||
""" | ||
|
||
def middleware(request): | ||
response = get_response(request) | ||
|
||
if hasattr(request, "auth") and request.auth: | ||
token_info = get_token_info(str(request.auth)) | ||
if token_info: | ||
response["x-ov-client-application-name"] = token_info.application_name | ||
response["x-ov-client-application-verified"] = token_info.verified | ||
|
||
return response | ||
|
||
return middleware |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters