Skip to content
This repository has been archived by the owner on Nov 4, 2024. It is now read-only.

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
argl committed Oct 7, 2024
1 parent d4e6212 commit c541896
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 12 deletions.
14 changes: 12 additions & 2 deletions httpobs/website/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
from httpobs.website.decorators import add_response_headers, sanitized_api_response, add_sunset_headers, check_for_deprecation_override_header
from httpobs.website.decorators import (
add_response_headers,
add_sunset_headers,
check_for_deprecation_override_header,
sanitized_api_response,
)

__all__ = ['add_response_headers', 'sanitized_api_response', 'add_sunset_headers', 'check_for_deprecation_override_header']
__all__ = [
'add_response_headers',
'sanitized_api_response',
'add_sunset_headers',
'check_for_deprecation_override_header',
]
7 changes: 6 additions & 1 deletion httpobs/website/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@
from httpobs.conf import API_ALLOW_VERBOSE_STATS_FROM_PUBLIC, API_COOLDOWN, DEVELOPMENT_MODE
from httpobs.scanner import scan
from httpobs.scanner.grader import GRADES, get_score_description
from httpobs.website import add_response_headers, sanitized_api_response, add_sunset_headers, check_for_deprecation_override_header
from httpobs.website import (
add_response_headers,
add_sunset_headers,
check_for_deprecation_override_header,
sanitized_api_response,
)
from httpobs.website.utils import valid_hostname

api = Blueprint('api', __name__)
Expand Down
24 changes: 15 additions & 9 deletions httpobs/website/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

from flask import jsonify, make_response, request


def add_sunset_headers():
"""
Adds a "Sunset" header to the response
"""

def decorator(fn):
@wraps(fn)
def wrapper(*args, **kwargs):
Expand All @@ -24,24 +26,28 @@ def check_for_deprecation_override_header(fn):
- If the header is set to "yes", it will return the response as normal
- If the header is set to anything else, it will return a 410 Gone response
"""

@wraps(fn)
def wrapper(*args, **kwargs):
if request.headers.get('X-Deprecation-Override', 'no').lower() == 'yes':
return fn(*args, **kwargs)
else:
return make_response("""
This API has been deprecated and is no longer available.
Please use https://observatory-api.mdn.mozilla.net/.
For details about the new endpint, see
return make_response(
"""
This API has been deprecated and is no longer available.
Please use https://observatory-api.mdn.mozilla.net/.
For details about the new endpint, see
https://github.com/mdn/mdn-http-observatory/blob/main/README.md#post-apiv2scan.
If you really want to continue with this endpoint for now,
please add a header to your request in the form of
If you really want to continue with this endpoint for now,
please add a header to your request in the form of
X-Deprecation-Override: yes
Be aware that this API will go away without further warning on Oct 31, 2024.
""", 410)
""",
410,
)

return wrapper

Expand Down

0 comments on commit c541896

Please sign in to comment.