Question: Is it possible automatically add `Access-Control-Allow-Origin` header to all responses which was initiated by ajax request (with header `X-Requested-With`) in Pyramid?

Answer: 
I've solved the problem using `set_request_factory`:

```
from pyramid.request import Request
from pyramid.request import Response

def request_factory(environ):
    request = Request(environ)
    if request.is_xhr:
        request.response = Response()
        request.response.headerlist = []
        request.response.headerlist.extend(
            (
                ('Access-Control-Allow-Origin', '*'),
                ('Content-Type', 'application/json')
            )
        )
    return request

config.set_request_factory(request_factory)

```
I could send file with Ajax from a server to another server :

```
import uuid

from pyramid.view import view_config

from pyramid.response import Response

class FManager:

    def __init__(self, request):
        self.request = request

    @view_config(route_name='f_manager', request_method='POST', renderer='json')
    def post(self):
        file_ = self.request.POST.items()
        content_type = str(file_[0][1].type).split('/')
        file_[0][1].filename = str(uuid.uuid4()) + '.' + content_type[1]
        file_id = self.request.storage.save(file_[0][1])

        response = Response(body="{'data':'success'}")
        response.headers.update({
            'Access-Control-Allow-Origin': '*',
        })

        return response

```