[ADD]web_well_known: manage web .well-known paths

h14437
This commit is contained in:
Sam Hasan
2024-07-17 17:05:05 +00:00
parent 4f2049e976
commit 1e88b3f2bc
8 changed files with 130 additions and 0 deletions

View File

@@ -0,0 +1,24 @@
# Part of Hibou Suite Professional. See LICENSE_PROFESSIONAL file for full copyright and licensing details.
from odoo import http
from odoo.http import request, content_disposition
class WebWellKnown(http.Controller):
@http.route('/.well-known/<path:path>', type='http', auth='public', methods=['GET'], csrf=False)
def well_known_path(self, path, **kwargs):
well_known_paths = request.env['well.known.path'].sudo()
well_known_record = well_known_paths.search([('path', '=', path)], limit=1)
if not well_known_record:
return http.Response(status=404) # Return a 404 Not Found if the path does not exist
if well_known_record.file:
text_content = well_known_record.file.decode('utf-8')
return request.make_response(
text_content, # Decode binary content to a string
headers=[('Content-Type', 'text/plain; charset=utf-8')]
)
return well_known_record.value or '' # Return the value if no binary content is present, or empty string if value is None