diff --git a/src/service/clmcservice/__init__.py b/src/service/clmcservice/__init__.py index 70c6e76cad9a94cfca999f2b6f54ab717627c2b8..3d56991b194b5c23f742f7205d35fa003fa60489 100644 --- a/src/service/clmcservice/__init__.py +++ b/src/service/clmcservice/__init__.py @@ -60,6 +60,8 @@ def main(global_config, **settings): config = Configurator(settings=settings) + config.add_tween('clmcservice.tweens.accept_header_tween_factory') + # add routes of the WHOAMI API config.add_route('whoami_endpoints', '/whoami/endpoints') config.add_route('whoami_endpoints_instance', 'whoami/endpoints/instance') diff --git a/src/service/clmcservice/tweens.py b/src/service/clmcservice/tweens.py new file mode 100644 index 0000000000000000000000000000000000000000..a0f9eba9b5a7b4ef5298d32a089c410bb1d31c21 --- /dev/null +++ b/src/service/clmcservice/tweens.py @@ -0,0 +1,36 @@ +#!/usr/bin/python3 +""" +// © University of Southampton IT Innovation Centre, 2018 +// +// Copyright in this software belongs to University of Southampton +// IT Innovation Centre of Gamma House, Enterprise Road, +// Chilworth Science Park, Southampton, SO16 7NS, UK. +// +// This software may not be used, sold, licensed, transferred, copied +// or reproduced in whole or in part in any manner or form or in or +// on any media by any person other than in accordance with the terms +// of the Licence Agreement supplied with the software, or otherwise +// without the prior written consent of the copyright owners. +// +// This software is distributed WITHOUT ANY WARRANTY, without even the +// implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +// PURPOSE, except where stated in the Licence Agreement supplied with +// the software. +// +// Created By : Nikolay Stanchev +// Created Date : 02-11-2018 +// Created for Project : FLAME +""" + + +def accept_header_tween_factory(handler, registry): + """ + Since clmc-service is currently based on JSON only, make sure an application/json header is passed with the request + """ + + def accept_header_tween(request): + request.accept = 'application/json' + response = handler(request) + return response + + return accept_header_tween