From f86a44b6372de257622821781bc852780bac0eaf Mon Sep 17 00:00:00 2001 From: Ben Busby <33362396+benbusby@users.noreply.github.com> Date: Thu, 11 Jun 2020 12:14:57 -0600 Subject: [PATCH] Removed no-cache enforcement, minor styling/formatting improvements --- app/request.py | 4 ++-- app/routes.py | 21 ++++++++++----------- app/utils/misc.py | 4 ++-- app/utils/routing_utils.py | 6 ++++-- 4 files changed, 18 insertions(+), 17 deletions(-) diff --git a/app/request.py b/app/request.py index 398ab71..fe7d3fb 100644 --- a/app/request.py +++ b/app/request.py @@ -22,8 +22,8 @@ def gen_user_agent(is_mobile): if is_mobile: return MOBILE_UA.format(mozilla, firefox) - else: - return DESKTOP_UA.format(mozilla, linux, firefox) + + return DESKTOP_UA.format(mozilla, linux, firefox) def gen_query(query, args, config, near_city=None): diff --git a/app/routes.py b/app/routes.py index 0139594..c60d4ac 100644 --- a/app/routes.py +++ b/app/routes.py @@ -1,22 +1,22 @@ -from app import app -from app.models.config import Config -from app.request import Request -from app.utils.misc import generate_user_keys, valid_user_session -from app.utils.routing_utils import * import argparse import base64 -from bs4 import BeautifulSoup -from cryptography.fernet import Fernet -from flask import g, jsonify, make_response, request, redirect, render_template, send_file, session -from functools import wraps import io import json import os import pickle import urllib.parse as urlparse -from requests import exceptions import uuid +from functools import wraps + import waitress +from flask import jsonify, make_response, request, redirect, render_template, send_file, session +from requests import exceptions + +from app import app +from app.models.config import Config +from app.request import Request +from app.utils.misc import valid_user_session +from app.utils.routing_utils import * def auth_required(f): @@ -87,7 +87,6 @@ def after_request_func(response): for key in session_list: session.pop(key) - response.headers["Cache-Control"] = "no-cache, no-store, must-revalidate" return response diff --git a/app/utils/misc.py b/app/utils/misc.py index 9bd580d..f959abe 100644 --- a/app/utils/misc.py +++ b/app/utils/misc.py @@ -1,7 +1,7 @@ from cryptography.fernet import Fernet from flask import current_app as app -SESSION_VALS = ['uuid', 'config', 'fernet_keys'] +REQUIRED_SESSION_VALUES = ['uuid', 'config', 'fernet_keys'] def generate_user_keys(cookies_disabled=False) -> dict: @@ -17,7 +17,7 @@ def generate_user_keys(cookies_disabled=False) -> dict: def valid_user_session(session): # Generate secret key for user if unavailable - for value in SESSION_VALS: + for value in REQUIRED_SESSION_VALUES: if value not in session: return False diff --git a/app/utils/routing_utils.py b/app/utils/routing_utils.py index cfe0b64..40f8a90 100644 --- a/app/utils/routing_utils.py +++ b/app/utils/routing_utils.py @@ -32,7 +32,8 @@ class RoutingUtils: def new_search_query(self) -> str: # Generate a new element key each time a new search is performed - self.session['fernet_keys']['element_key'] = generate_user_keys(cookies_disabled=self.cookies_disabled)['element_key'] + self.session['fernet_keys']['element_key'] = generate_user_keys( + cookies_disabled=self.cookies_disabled)['element_key'] q = self.request_params.get('q') @@ -46,7 +47,8 @@ class RoutingUtils: pass # Reset text key - self.session['fernet_keys']['text_key'] = generate_user_keys(cookies_disabled=self.cookies_disabled)['text_key'] + self.session['fernet_keys']['text_key'] = generate_user_keys( + cookies_disabled=self.cookies_disabled)['text_key'] # Format depending on whether or not the query is a "feeling lucky" query self.feeling_lucky = q.startswith('! ')