def make_callbacks(routes):

    def req_callback(req):

        host = ''
        port = None

        # req.headers['Host']=req.host

        for src, dst in routes:
            if src[0] and fnmatch.fnmatch(req.host, src[0]):
                if src[1] and req.port != src[1]:
                    continue
                host = dst[0] or '127.0.0.1'
                port = dst[1] or 80 
                break

        if not host:
            body = 'No route for %s:%d' % (req.host, req.port)
            return quickproxy.ResponseObj(body=body, headers={'Content-Type': 'text/plain'})
        else:
            req.host, req.port = host, port

        # todo: deal with chunked transfer encoding headers

        return req


    def ssl_callback(req):
        req.port = 80
        req.protocol = 'http'
        req.headers.update({'x-forwarded-proto': 'https'})
        return req_callback(req)

    return req_callback, ssl_callback
dataset/ETHPy150Open braceio/localdev/localdev/server.py/make_callbacks/original