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
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'
|
||||
)
|
9
wellknowns/views/static.py
Normal file
9
wellknowns/views/static.py
Normal file
|
@ -0,0 +1,9 @@
|
|||
from django.views.generic.base import RedirectView
|
||||
from django.contrib.staticfiles.templatetags.staticfiles import static
|
||||
|
||||
|
||||
def redirect_to_static(file):
|
||||
return RedirectView.as_view(url=static('wellknowns/' + file))
|
||||
|
||||
|
||||
keybase = redirect_to_static('keybase.txt')
|
Loading…
Add table
Add a link
Reference in a new issue