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

handle OPTIONS requests on upload endpoints #2384

Merged
merged 1 commit into from
Oct 4, 2022
Merged
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
24 changes: 16 additions & 8 deletions superdesk/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,29 @@
logger = logging.getLogger(__name__)


@bp.route("/upload/<path:media_id>/raw", methods=["GET"])
def handle_cors():
"""Return headers to avoid CORS problems."""
response = make_response()
response.headers.add("Access-Control-Allow-Origin", "*")
response.headers.add("Access-Control-Allow-Headers", "*")
response.headers.add("Access-Control-Allow-Methods", "POST")
return response


@bp.route("/upload/<path:media_id>/raw", methods=["GET", "OPTIONS"])
@blueprint_auth()
def get_upload_as_data_uri_bc(media_id):
if request.method == "OPTIONS":
return handle_cors()
"""Keep previous url for backward compatibility"""
return redirect(upload_url(media_id))


@bp.route("/upload-raw/<path:media_id>", methods=["GET"])
@bp.route("/upload-raw/<path:media_id>", methods=["GET", "OPTIONS"])
@blueprint_auth()
def get_upload_as_data_uri(media_id):
if request.method == "OPTIONS":
return handle_cors()
if not request.args.get("resource"):
media_file = app.media.get_by_filename(media_id)
else:
Expand All @@ -63,12 +76,7 @@ def get_upload_as_data_uri(media_id):
@blueprint_auth()
def upload_config_file():
if request.method == "OPTIONS":
# return headers to avoid CORS problems
response = make_response()
response.headers.add("Access-Control-Allow-Origin", "*")
response.headers.add("Access-Control-Allow-Headers", "*")
response.headers.add("Access-Control-Allow-Methods", "POST")
return response
return handle_cors()

_resource = request.args.get("resource")
if not _resource:
Expand Down