Add basic support for /.well-known/host-meta(.json)?, not much info in it so far but it works
This commit is contained in:
parent
0419a844ce
commit
00d7a29b2d
6 changed files with 54 additions and 1 deletions
|
@ -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'),
|
||||
]
|
||||
|
|
2
wellknowns/views/__init__.py
Normal file
2
wellknowns/views/__init__.py
Normal file
|
@ -0,0 +1,2 @@
|
|||
from .static import keybase
|
||||
from .host_meta import host_meta_xml, host_meta_json
|
35
wellknowns/views/host_meta.py
Normal file
35
wellknowns/views/host_meta.py
Normal 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'
|
||||
)
|
Loading…
Add table
Add a link
Reference in a new issue