Skip to content

Commit

Permalink
always ensure https scheme when using url_for and _external=True
Browse files Browse the repository at this point in the history
  • Loading branch information
dginev committed Dec 12, 2024
1 parent 5d5934a commit 5f40da6
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions browse/controllers/list_page/author.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ def _make_json_entry (metadata: DocMetadata) -> Dict[str, str]:
# TODO: ps format? It doesn't seem like this is possible in the arXiv-NG implementation
entry['formats'] = {
'html': metadata.canonical_url(),
'pdf': url_for('dissemination.pdf', arxiv_id=metadata.arxiv_id_v, _external=True)
}
'pdf': url_for('dissemination.pdf', arxiv_id=metadata.arxiv_id_v, _external=True, _scheme='https')
}

# 'id' field
# TODO: This seems to be redundant with entry['formats']['html'] right above
Expand Down Expand Up @@ -247,7 +247,7 @@ def _add_atom_feed_entry (metadata: DocMetadata, feed: Element, atom2: bool = Fa

SubElement(entry, 'link', attrib={
'title': 'pdf',
'href': url_for('dissemination.pdf', arxiv_id=metadata.arxiv_id_v, _external=True),
'href': url_for('dissemination.pdf', arxiv_id=metadata.arxiv_id_v, _external=True, _scheme='https'),
'rel': 'alternate',
'type': 'application/pdf'
})
Expand Down
2 changes: 1 addition & 1 deletion browse/formatting/metatags.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def meta_tag_metadata(metadata: DocMetadata, truncate: bool = False) -> List:
if cod:
meta_tags.append(_mtag("citation_online_date", cod))

pdfurl=url_for("dissemination.pdf", arxiv_id=metadata.arxiv_id, _external=True)
pdfurl=url_for("dissemination.pdf", arxiv_id=metadata.arxiv_id, _external=True, _scheme='https')
meta_tags.append(_mtag("citation_pdf_url",pdfurl))

meta_tags.append(_mtag("citation_arxiv_id", str(metadata.arxiv_id)))
Expand Down
4 changes: 2 additions & 2 deletions browse/routes/dissemination.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def redirect_pdf(arxiv_id: str, archive=None): # type: ignore
"""
arxiv_id = f"{archive}/{arxiv_id}" if archive else arxiv_id
return redirect(url_for('.pdf', arxiv_id=arxiv_id, _external=True), 301)
return redirect(url_for('.pdf', arxiv_id=arxiv_id, _external=True, _scheme='https'), 301)


@blueprint.route("/pdf/<string:archive>/<string:arxiv_id>", methods=['GET', 'HEAD'])
Expand All @@ -59,7 +59,7 @@ def pdf(arxiv_id: str, archive=None): # type: ignore
"""

if request.query_string: # redirect to strip off any useless query strings
return redirect(url_for('.pdf', arxiv_id=arxiv_id, archive=archive, _external=True), 301)
return redirect(url_for('.pdf', arxiv_id=arxiv_id, archive=archive, _external=True, _scheme='https'), 301)
return get_pdf_resp(arxiv_id, archive)


Expand Down

0 comments on commit 5f40da6

Please sign in to comment.