<commit_before># -*- coding: utf-8 -*-
# ###
# Copyright (c) 2013, Rice University
# This software is subject to the provisions of the GNU Affero General
# Public License version 3 (AGPLv3).
# See LICENCE.txt for details.
# ###

from pyramid.events import NewRequest

def add_cors_headers(request, response):
    settings = request.registry.settings
    acac = settings['cors.access_control_allow_credentials']
    acao = settings['cors.access_control_allow_origin'].split()
    acah = settings['cors.access_control_allow_headers']
    acam = settings['cors.access_control_allow_methods']
    if acac:
        response.headerlist.append(
                ('Access-Control-Allow-Credentials', acac))
    if acao:
        if request.host in acao:
            response.headerlist.append(
                ('Access-Control-Allow-Origin', request.host))
        else:   
            response.headerlist.append(
                ('Access-Control-Allow-Origin', acao[0]))
    if acah:
        response.headerlist.append(
                ('Access-Control-Allow-Headers', acah))
    if acam:
        response.headerlist.append(
                ('Access-Control-Allow-Methods', acam))

def new_request_subscriber(event):<commit_msg>Fix Access-Control-Allow-Origin to return the request origin<commit_after># -*- coding: utf-8 -*-
# ###
# Copyright (c) 2013, Rice University
# This software is subject to the provisions of the GNU Affero General
# Public License version 3 (AGPLv3).
# See LICENCE.txt for details.
# ###

from pyramid.events import NewRequest

def add_cors_headers(request, response):
    settings = request.registry.settings
    acac = settings['cors.access_control_allow_credentials']
    acao = settings['cors.access_control_allow_origin'].split()
    acah = settings['cors.access_control_allow_headers']
    acam = settings['cors.access_control_allow_methods']
    if acac:
        response.headerlist.append(
                ('Access-Control-Allow-Credentials', acac))
    if acao:
        if request.headers.get('Origin') in acao:
            response.headerlist.append(
                ('Access-Control-Allow-Origin', request.headers.get('Origin')))
        else:   
            response.headerlist.append(
                ('Access-Control-Allow-Origin', acao[0]))
    if acah:
        response.headerlist.append(
                ('Access-Control-Allow-Headers', acah))
    if acam:
        response.headerlist.append(
                ('Access-Control-Allow-Methods', acam))

def new_request_subscriber(event):
{'fraction_non_alphanumeric': 0.11631599841206829, 'fraction_numerical': 0.006351726875744343, 'mean_word_length': 2.876923076923077, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1964647', 'n_tokens_mistral': 739, 'n_tokens_neox': 720, 'n_words': 157}