Skip to content

Commit

Permalink
Adjust URLs to make coda work on HTTP or HTTPS.
Browse files Browse the repository at this point in the history
  • Loading branch information
somexpert committed Mar 26, 2024
1 parent e85c6ed commit bb52cc8
Show file tree
Hide file tree
Showing 18 changed files with 98 additions and 95 deletions.
3 changes: 0 additions & 3 deletions coda/coda_mdstore/mdstore_oai.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,6 @@ def makeDataRecord(
bagInfoDict = {}
for bagInfoObject in bagInfoObjectList:
bagInfoDict[bagInfoObject.field_name] = bagInfoObject.field_body
stripdomain = domain
if stripdomain.startswith("http://"):
stripdomain = stripdomain[len("http://"):]
dcDict = {}
identifiers = [bagObject.name]
if "External-Identifier" in bagInfoDict:
Expand Down
4 changes: 2 additions & 2 deletions coda/coda_mdstore/presentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def getFileHandle(codaId, codaPath):
for node in nodeList:
url_parts = urllib.parse.urlparse(node.node_url)
url = urllib.parse.urljoin(
"http://%s" % url_parts.hostname,
"%s://%s" % (url_parts.scheme, url_parts.hostname),
os.path.join(
url_parts.path,
"store/pairtree_root",
Expand Down Expand Up @@ -386,7 +386,7 @@ def nodeEntry(node, webRoot=None):
node_status.text = node.get_status_display()
atomXML = wrapAtom(
xml=nodeXML,
id='http://%s/node/%s/' % (webRoot, node.node_name),
id='%s/node/%s/' % (webRoot, node.node_name),
title=node.node_name,
author=APP_AUTHOR['name'],
author_uri=APP_AUTHOR['uri'],
Expand Down
1 change: 0 additions & 1 deletion coda/coda_mdstore/resourcesync.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ def capabilitylist(

class BaseSitemap(Sitemap):
lastmod = None
protocol = 'http'

def items(self):
# return the list of all the bags sorted by bagging_date
Expand Down
2 changes: 1 addition & 1 deletion coda/coda_mdstore/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def test_xml_has_node_attributes(self):

def test_xml_id(self):
node = factories.NodeFactory.build()
web_root = 'example.com'
web_root = 'http://example.com'

tree = presentation.nodeEntry(node, web_root)
xml_obj = convert_etree(tree)
Expand Down
21 changes: 11 additions & 10 deletions coda/coda_mdstore/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,8 @@ def bagHTML(request, identifier):
total_events = None
try:
filters = {'linked_object_id': bag}
event_json_url = 'http://%s/event/search.json?%s' % (
event_json_url = '%s://%s/event/search.json?%s' % (
request.scheme,
# TODO: Maybe this should be configurable?
request.META.get('HTTP_HOST'),
urlencode(filters)
Expand Down Expand Up @@ -821,7 +822,7 @@ def app_bag(request, identifier=None):
objectToXMLFunction=objectsToXML,
feedId=request.path[1:],
title="Bag Feed",
webRoot='http://%s' % request.META['HTTP_HOST'],
webRoot='%s://%s' % (request.scheme, request.META['HTTP_HOST']),
idAttr="name",
request=request,
page=page,
Expand All @@ -840,8 +841,8 @@ def app_bag(request, identifier=None):
# attempt to parse POST'd XML
xml = request.body
bagObject, bagInfos = createBag(xml)
loc = 'http://%s/APP/bag/%s/' % (
request.META['HTTP_HOST'], bagObject.name
loc = '%s://%s/APP/bag/%s/' % (
request.scheme, request.META['HTTP_HOST'], bagObject.name
)
returnXML = objectsToXML(bagObject)
returnEntry = bagatom.wrapAtom(
Expand Down Expand Up @@ -924,7 +925,7 @@ def app_node(request, identifier=None):
return HttpResponseNotFound(
"There is no node with name '%s'." % identifier
)
atomXML = nodeEntry(node, webRoot=request.META['HTTP_HOST'])
atomXML = nodeEntry(node, webRoot=request.scheme + '://' + request.META['HTTP_HOST'])
atomText = XML_HEADER % etree.tostring(atomXML, pretty_print=True)
resp = HttpResponse(atomText, content_type="application/atom+xml")
resp.status_code = 200
Expand All @@ -943,7 +944,7 @@ def app_node(request, identifier=None):
objectToXMLFunction=bagatom.nodeToXML,
feedId=request.path[1:],
title="Node Feed",
webRoot='http://%s' % request.META['HTTP_HOST'],
webRoot='%s://%s' % (request.scheme, request.META['HTTP_HOST']),
idAttr="node_name",
nameAttr="node_name",
request=request,
Expand Down Expand Up @@ -975,10 +976,10 @@ def app_node(request, identifier=None):
"Conflict with already-existing resource.\n",
status=409, content_type="text/plain"
)
loc = 'http://%s/APP/node/%s/' % (
request.META['HTTP_HOST'], node.node_name
loc = '%s://%s/APP/node/%s/' % (
request.scheme, request.META['HTTP_HOST'], node.node_name
)
atomXML = nodeEntry(node, webRoot=request.META['HTTP_HOST'])
atomXML = nodeEntry(node, webRoot=request.scheme + '://' + request.META['HTTP_HOST'])
atomText = XML_HEADER % etree.tostring(atomXML, pretty_print=True)
resp = HttpResponse(atomText, content_type="application/atom+xml")
resp.status_code = 201
Expand All @@ -994,7 +995,7 @@ def app_node(request, identifier=None):
return HttpResponseBadRequest(str(e))

node.save()
atomXML = nodeEntry(node, webRoot=request.META['HTTP_HOST'])
atomXML = nodeEntry(node, webRoot=request.scheme + '://' + request.META['HTTP_HOST'])
atomText = XML_HEADER % etree.tostring(atomXML, pretty_print=True)
resp = HttpResponse(atomText, content_type="application/atom+xml")
resp.status_code = 200
Expand Down
2 changes: 1 addition & 1 deletion coda/coda_oaipmh/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def index(request):
siteBaseURL = baseURL
if baseURL[-1] != '/':
baseURL = baseURL + '/'
identifyDict['baseURL'] = "http://" + baseURL + "oai/"
identifyDict['baseURL'] = request.scheme + "://" + baseURL + "oai/"
serverBase = mdstore_oai.OAIInterface(
identifyDict=identifyDict,
domain=siteBaseURL
Expand Down
23 changes: 14 additions & 9 deletions coda/coda_replication/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,21 +179,24 @@ def queue_search_JSON(request):
[
{
'rel': 'self',
'href': "http://%s%s?%s" % (
'href': "%s://%s%s?%s" % (
request.scheme,
request.META.get('HTTP_HOST'),
request.path, urllib.parse.urlencode(current_page_args)
)
},
{
'rel': 'first',
'href': "http://%s%s?%s" % (
'href': "%s://%s%s?%s" % (
request.scheme,
request.META.get('HTTP_HOST'),
request.path, urllib.parse.urlencode(first_page_args)
)
},
{
'rel': 'last',
'href': "http://%s%s?%s" % (
'href': "%s://%s%s?%s" % (
request.scheme,
request.META.get('HTTP_HOST'),
request.path, urllib.parse.urlencode(last_page_args)
)
Expand All @@ -206,7 +209,8 @@ def queue_search_JSON(request):
rel_links.append(
{
'rel': 'previous',
'href': "http://%s%s?%s" % (
'href': "%s://%s%s?%s" % (
request.scheme,
request.META.get('HTTP_HOST'),
request.path, urllib.parse.urlencode(args)
)
Expand All @@ -218,7 +222,8 @@ def queue_search_JSON(request):
rel_links.append(
{
'rel': 'next',
'href': "http://%s%s?%s" % (
'href': "%s://%s%s?%s" % (
request.scheme,
request.META.get('HTTP_HOST'),
request.path, urllib.parse.urlencode(args)
)
Expand Down Expand Up @@ -323,7 +328,7 @@ def queue(request, identifier=None):
)
identifier = queueObject.ark
queueObjectXML = queueEntryToXML(queueObject)
loc = 'http://%s/%s/' % (request.META['HTTP_HOST'], queueObject.ark)
loc = '%s://%s/%s/' % (request.scheme, request.META['HTTP_HOST'], queueObject.ark)
atomXML = wrapAtom(
xml=queueObjectXML,
id=loc,
Expand Down Expand Up @@ -351,7 +356,7 @@ def queue(request, identifier=None):
queueObjectXML = queueEntryToXML(queueObject)
atomXML = wrapAtom(
xml=queueObjectXML,
id='http://%s/%s/' % (request.META['HTTP_HOST'], queueObject.ark),
id='%s://%s/%s/' % (request.scheme, request.META['HTTP_HOST'], queueObject.ark),
title=queueObject.ark,
)
atomText = b'<?xml version="1.0"?>\n%b' % etree.tostring(
Expand All @@ -371,7 +376,7 @@ def queue(request, identifier=None):
queueObjectXML = queueEntryToXML(queueObject)
atomXML = wrapAtom(
xml=queueObjectXML,
id='http://%s/%s/' % (request.META['HTTP_HOST'], queueObject.ark),
id='%s://%s/%s/' % (request.scheme, request.META['HTTP_HOST'], queueObject.ark),
title=queueObject.ark,
author=APP_AUTHOR.get('name', None),
author_uri=APP_AUTHOR.get('uri', None)
Expand Down Expand Up @@ -415,7 +420,7 @@ def queue_list(request):
objectToXMLFunction=queueEntryToXML,
feedId=request.path[1:],
title='Queue Entry Feed',
webRoot='http://{0}'.format(request.META['HTTP_HOST']),
webRoot='{0}://{1}'.format(request.scheme, request.META['HTTP_HOST']),
idAttr='ark',
nameAttr='ark',
request=request,
Expand Down
22 changes: 11 additions & 11 deletions coda/coda_validate/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,16 +410,16 @@ def app_validate(request, identifier=None):
validateObjectXML = validateToXML(validateObject)
atomXML = wrapAtom(
xml=validateObjectXML,
id='http://%s/APP/validate/%s/' % (
request.META['HTTP_HOST'], validateObject.identifier
id='%s://%s/APP/validate/%s/' % (
request.scheme, request.META['HTTP_HOST'], validateObject.identifier
),
title=validateObject.identifier,
)
atomText = XML_HEADER % etree.tostring(atomXML, pretty_print=True)
resp = HttpResponse(atomText, content_type="application/atom+xml")
resp.status_code = 201
resp['Location'] = 'http://%s/APP/validate/%s/' % \
(request.META['HTTP_HOST'], validateObject.identifier)
resp['Location'] = '%s://%s/APP/validate/%s/' % \
(request.scheme, request.META['HTTP_HOST'], validateObject.identifier)
elif request.method == 'HEAD':
resp = HttpResponse(content_type="application/atom+xml")
resp.status_code = 200
Expand All @@ -432,7 +432,7 @@ def app_validate(request, identifier=None):
paginator=Paginator(validates, 20),
objectToXMLFunction=validateToXML,
feedId=request.path[1:],
webRoot='http://%s' % request.META.get('HTTP_HOST'),
webRoot='%s://%s' % (request.scheme, request.META.get('HTTP_HOST')),
title="validate Entry Feed",
idAttr="identifier",
nameAttr="identifier",
Expand All @@ -453,8 +453,8 @@ def app_validate(request, identifier=None):
validateObjectXML = validateToXML(returnValidate)
atomXML = wrapAtom(
xml=validateObjectXML,
id='http://%s/APP/validate/%s/' % (
request.META['HTTP_HOST'], identifier
id='%s://%s/APP/validate/%s/' % (
request.scheme, request.META['HTTP_HOST'], identifier
),
title=identifier,
)
Expand All @@ -473,8 +473,8 @@ def app_validate(request, identifier=None):
validateObjectXML = validateToXML(returnValidate)
atomXML = wrapAtom(
xml=validateObjectXML,
id='http://%s/APP/validate/%s/' % (
request.META['HTTP_HOST'], identifier
id='%s://%s/APP/validate/%s/' % (
request.scheme, request.META['HTTP_HOST'], identifier
),
title=identifier,
author=APP_AUTHOR.get('name', None),
Expand All @@ -496,8 +496,8 @@ def app_validate(request, identifier=None):
validate_object.delete()
atomXML = wrapAtom(
xml=validateObjectXML,
id='http://%s/APP/validate/%s/' % (
request.META['HTTP_HOST'], identifier
id='%s://%s/APP/validate/%s/' % (
request.scheme, request.META['HTTP_HOST'], identifier
),
title=identifier,
)
Expand Down
2 changes: 1 addition & 1 deletion coda/templates/coda_replication/queue.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
{% for entry in entries %}
<tr>
<td class="data" style="vertical-align:middle">
<i class="icon-tag"></i> <a href='http://{{ request.META.HTTP_HOST }}/queue/{{ entry.ark }}/'>{{ entry.ark }}</a>
<i class="icon-tag"></i> <a href='{{ request.scheme }}://{{ request.META.HTTP_HOST }}/queue/{{ entry.ark }}/'>{{ entry.ark }}</a>
</td>
<td class="data" style="vertical-align:middle">
<i class="icon-asterisk"></i>
Expand Down
2 changes: 1 addition & 1 deletion coda/templates/coda_replication/queue_entry.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<td><i class="icon-list-ol"></i> {{ record.queue_position }}</td>
</tr>
</table>
<a class="btn btn-success btn-large" href="http://{{ request.META.HTTP_HOST }}/APP/queue/{{ record.ark }}/">
<a class="btn btn-success btn-large" href="{{ request.scheme }}://{{ request.META.HTTP_HOST }}/APP/queue/{{ record.ark }}/">
ATOMPUB <i class="icon-rss"></i>
</a>
{% endblock %}
2 changes: 1 addition & 1 deletion coda/templates/coda_replication/search.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
{% for entry in entries.object_list %}
<tr>
<td class="data" style="vertical-align:middle">
<i class="icon-tag"></i> <a href='http://{{ request.META.HTTP_HOST }}/queue/{{ entry.ark }}'>{{ entry.ark }}</a>
<i class="icon-tag"></i> <a href='{{ request.scheme }}://{{ request.META.HTTP_HOST }}/queue/{{ entry.ark }}'>{{ entry.ark }}</a>
</td>
<td class="data" style="vertical-align:middle">
<i class="icon-asterisk"></i>
Expand Down
2 changes: 1 addition & 1 deletion coda/templates/coda_validate/validate.html
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
</div>
<div class="row">
<div class="span6">
<a class="btn btn-success btn-large" href="http://{{ request.META.HTTP_HOST }}/APP/validate/{{ validate.identifier }}/">
<a class="btn btn-success btn-large" href="{{ request.scheme }}://{{ request.META.HTTP_HOST }}/APP/validate/{{ validate.identifier }}/">
ATOMPUB <i class="icon-rss"></i>
</a>
</div>
Expand Down
Loading

0 comments on commit bb52cc8

Please sign in to comment.