From 6c8b9dfc459b3837c2c5f89556a41533c5956773 Mon Sep 17 00:00:00 2001 From: Tyler Perkins Date: Thu, 9 Mar 2023 20:28:41 -0500 Subject: [PATCH] Add meme name to header --- src/api/get.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/api/get.py b/src/api/get.py index 97a6bb9..edc86da 100644 --- a/src/api/get.py +++ b/src/api/get.py @@ -1,6 +1,6 @@ from flask_restx import Namespace, Resource, fields from flask_restx import reqparse -from flask import make_response, abort, request +from flask import make_response, abort, request, Response from minio.commonconfig import Tags from werkzeug.datastructures import FileStorage from api.clientGetter import getClientSafely @@ -103,7 +103,11 @@ class getRandomFile(Resource): if client is None: abort(500, "S3 failed to start") choice = random.choice(tuple(client.getCurrentMemeList())) - return make_response(client.getMeme(choice)) + + response = make_response(client.getMeme(choice)) + response.headers['X-Meme-Name'] = choice + + return response @api.route('/psuedorandom') @api.doc(description="Returns a psuedorandom meme. Will not return the same meme for a set number of requests") @@ -129,5 +133,8 @@ class getRandomFile(Resource): logging.debug("Contents of cache : " + str(self.cache)) - return make_response(client.getMeme(choice)) + response = make_response(client.getMeme(choice)) + response.headers['X-Meme-Name'] = choice + + return response