Add basic support for /.well-known/host-meta(.json)?, not much info in it so far but it works

This commit is contained in:
Danielle McLean 2017-10-27 12:25:17 +11:00
parent 0419a844ce
commit 00d7a29b2d
Signed by: 00dani
GPG key ID: 5A5D2D1AFF12EEC5
6 changed files with 54 additions and 1 deletions

View file

@ -5,4 +5,6 @@ from . import views
app_name = 'wellknowns'
urlpatterns = [
url(r'^keybase.txt$', views.keybase, name='keybase'),
url(r'^host-meta$', views.host_meta_xml, name='host-meta'),
url(r'^host-meta.json$', views.host_meta_json, name='host-meta.json'),
]

View file

@ -0,0 +1,2 @@
from .static import keybase
from .host_meta import host_meta_xml, host_meta_json

View file

@ -0,0 +1,35 @@
from django.http import HttpResponse
from django.conf import settings
from lemoncurry.templatetags.lemoncurry_tags import get_package_json
from xrd import XRD, Attribute, Element, Link
def add_links(dest):
package = get_package_json()
links = (
Link(rel='license', href='https://creativecommons.org/licenses/by-sa/4.0/'),
Link(rel='code-repository', href=package['repository']),
)
dest.extend(links)
def host_meta(request):
h = XRD()
h.attributes.append(Attribute('xmlns:hm', 'http://host-meta.net/ns/1.0'))
h.elements.append(Element('hm:Host', request.META['HTTP_HOST']))
add_links(h.links)
return h
def host_meta_xml(request):
return HttpResponse(
host_meta(request).to_xml().toprettyxml(indent=' ', encoding='utf-8'),
content_type='application/xrd+xml',
)
def host_meta_json(request):
return HttpResponse(
host_meta(request).to_json(),
content_type='application/json'
)