<commit_before>import logging

from fnmatch import fnmatch
from tornado import web
from qotr.config import config

L = logging.getLogger(__name__)
ALLOWED_ORIGINS = [o.strip() for o in config.allowed_origin.split(',')]

def set_cors_headers(handler):
    '''
    Given a handler, set the CORS headers on it.
    '''


    origin = handler.request.host.split(':')[0]

    L.debug('Setting CORS headers for: %s based on %s', origin,
            ALLOWED_ORIGINS)
    if origin in ALLOWED_ORIGINS or any(fnmatch(origin, o)
                                        for o in ALLOWED_ORIGINS):
        handler.set_header("Access-Control-Allow-Origin", origin)
        handler.set_header("Access-Control-Allow-Headers", "Content-Type")

# pylint: disable=W0223
class Base(web.RequestHandler):
    '''
    A base request handler.
    '''

    def prepare(self):

        protocol = self.request.headers.get('x-forwarded-proto')

        if config.redirect_to_https and \
           self.request.method == 'GET' and \
           protocol == 'http':
            self.redirect('https://{}{}'.format(
                self.request.host.split(':')[0], self.request.path
            ), permanent=True)<commit_msg>Look for origin header instead of using host<commit_after>import logging

from fnmatch import fnmatch
from tornado import web
from qotr.config import config

L = logging.getLogger(__name__)
ALLOWED_ORIGINS = [o.strip() for o in config.allowed_origin.split(',')]

def set_cors_headers(handler):
    '''
    Given a handler, set the CORS headers on it.
    '''


    origin = handler.request.headers.get('Origin')

    L.debug('Setting CORS headers for: %s based on %s', origin,
            ALLOWED_ORIGINS)
    if origin in ALLOWED_ORIGINS or any(fnmatch(origin, o)
                                        for o in ALLOWED_ORIGINS):
        handler.set_header("Access-Control-Allow-Origin", origin)
        handler.set_header("Access-Control-Allow-Headers", "Content-Type")

# pylint: disable=W0223
class Base(web.RequestHandler):
    '''
    A base request handler.
    '''

    def prepare(self):

        protocol = self.request.headers.get('x-forwarded-proto')

        if config.redirect_to_https and \
           self.request.method == 'GET' and \
           protocol == 'http':
            self.redirect('https://{}{}'.format(
                self.request.host.split(':')[0], self.request.path
            ), permanent=True)
{'fraction_non_alphanumeric': 0.12324814509480626, 'fraction_numerical': 0.004534212695795548, 'mean_word_length': 2.6008902077151337, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1032906', 'n_tokens_mistral': 737, 'n_tokens_neox': 713, 'n_words': 174}