diff --git a/daemon_get_post.py b/daemon_get_post.py index f1a853f7a..ffe899d6e 100644 --- a/daemon_get_post.py +++ b/daemon_get_post.py @@ -33,6 +33,7 @@ from httpcodes import http_401 from httpcodes import http_403 from httpcodes import http_404 from httpheaders import set_headers +from httpheaders import set_html_post_headers from httpheaders import login_headers from httpheaders import redirect_headers from httprequests import request_http @@ -161,8 +162,9 @@ def _show_post_from_file(self, post_filename: str, liked_by: str, auto_cw_cache) msg = msg.encode('utf-8') msglen = len(msg) - set_headers(self, 'text/html', msglen, - cookie, calling_domain, False) + set_html_post_headers(self, msglen, + cookie, calling_domain, False, + post_json_object) write2(self, msg) fitness_performance(getreq_start_time, fitness, '_GET', 'show_post_from_file', diff --git a/httpheaders.py b/httpheaders.py index 25277b4b1..d26e72598 100644 --- a/httpheaders.py +++ b/httpheaders.py @@ -14,6 +14,7 @@ from utils import string_contains from utils import get_instance_url from utils import data_dir from utils import save_json +from utils import remove_id_ending def login_headers(self, file_format: str, length: int, @@ -164,6 +165,25 @@ def set_headers(self, file_format: str, length: int, cookie: str, self.end_headers() +def set_html_post_headers(self, length: int, cookie: str, + calling_domain: str, permissive: bool, + post_json_object: {}) -> None: + """A HTML format post representing an individual ActivityPub post + """ + _set_headers_base(self, 'text/html', length, cookie, calling_domain, + permissive) + if post_json_object.get('id'): + # Discover activitypub version of the html post + # https://swicg.github.io/activitypub-html-discovery/#http-link-header + post_id = remove_id_ending(post_json_object['id']) + ap_link = \ + '<' + post_id + '>; rel="alternate"; ' + \ + 'type="application/activity+json"' + self.send_header('Link', ap_link) + + self.end_headers() + + def set_headers_head(self, file_format: str, length: int, etag: str, calling_domain: str, permissive: bool, last_modified_time_str: str) -> None: