How to use the bottle.response.set_header function in bottle

To help you get started, we’ve selected a few bottle examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jamesmeneghello / pynab / pynab / api.py View on Github external
def get_nfo(dataset=None):
    if auth():
        id = request.query.guid or None
        if id:
            with db_session() as db:
                release = db.query(Release).join(NFO).filter(Release.id == id).first()
                if release:
                    data = release.nfo.data
                    response.set_header('Content-type', 'application/x-nfo')
                    response.set_header('Content-Disposition', 'attachment; filename="{0}"'
                                        .format(release.search_name.replace(' ', '_') + '.nfo')
                    )
                    return gzip.decompress(data)
                else:
                    return api_error(300)
        else:
            return api_error(200)
    else:
        return api_error(100)
github Scout24 / afp-core / src / main / python / aws_federation_proxy / wsgi_api / wsgi_api.py View on Github external
def new_function(*args, **kwargs):
            proxy = initialize_federation_proxy(user=user)
            response.set_header('X-Username', proxy.user)
            return_value = old_function(proxy, *args, **kwargs)
            response.content_type = 'application/json; charset=utf-8'
            return simplejson.dumps(return_value)
        return new_function
github eavatar / eavatar-me / src / ava / web / service.py View on Github external
"""
    Set CORS headers
    """
    if request.method == 'GET':
        response.set_header(b'Access-Control-Allow-Origin', b'*')
        return

    if request.method == 'OPTIONS':
        response.set_header(b'Access-Control-Allow-Methods',
                            b'GET, PUT, HEAD, DELETE, OPTIONS')
        response.set_header(b'Access-Control-Allow-Headers',
                            b'authorization')

    client_origin = request.get_header(b'Origin', b'*')
    # for PUT and DELETE operations, echo back the given Origin header.
    response.set_header(b'Access-Control-Allow-Origin', client_origin)
github mak / ipad / srv / cmd.py View on Github external
uid=request.forms.get('uid')
    ssid=request.forms.get('ssid',None)
    ss = user.get_session(ssid)
    if not ss:
        abort(404,'This is not a session you are lookig for')

    if ss.idb.uid != uid:
        abort(404,'This is not a idb you are lookig for')

    path = os.path.join(config.STOREDIR,ss.idb.uid,str(ss.ssid),ss.hash + '.idb')
    path = os.path.realpath(path)
    if not path.startswith(config.STOREDIR):
        abort(500,'I dont like it...')

    with open(path) as f: data= f.read()
    response.set_header('X-IDB-Name',ss.idb.name)
    return data
github rcarmo / bottle-fever / lib / decorators.py View on Github external
    @functools.wraps(callback)
    def wrapper(*args, **kwargs):
        body = callback(*args, **kwargs)
        try:
            body = json.dumps(body)
            # Set content type only if serialization succesful
            response.content_type = 'application/json'
        except Exception, e:
            return body

        callback_function = request.query.get('callback')
        if callback_function:
            body = b''.join([callback_function, '(', body, ')'])
            response.content_type = 'text/javascript'

        response.set_header('Last-Modified', time.strftime(gmt_format_string, time.gmtime()))
        response.set_header('ETag', binascii.b2a_base64(hashlib.sha1(body).digest()).strip())
        response.set_header('Content-Length', len(body))
        return body
    return wrapper
github hasname / feedgen / feedgen_hasname / __init__.py View on Github external
job_company = item.cssselect('.jbInfoin h4 a')[0].get('title')

            job_desc = item.cssselect('.jbInfoTxt')[0].text_content()
            content = '<h3>{}</h3><p>{}</p>'.format(
                html.escape(job_company), html.escape(job_desc)
            )

            entry = feed.add_entry()
            entry.content(content, type='xhtml')
            entry.id(job_url)
            entry.link(href=job_url)
            entry.title(job_title)

        bottle.response.set_header('Cache-Control', 'max-age=300,public')
        bottle.response.set_header('Content-Type', 'application/atom+xml')

        return feed.atom_str()
github rcarmo / yaki-tng / lib / decorators.py View on Github external
        @functools.wraps(callback)
        def wrapper(*args, **kwargs):
            expires = int(time.time() + seconds)
            expires = time.strftime(gmt_format_string, time.gmtime(expires))
            response.set_header('Expires', expires)
            if seconds:
                pragma = 'public'
            else:
                pragma = 'no-cache, must-revalidate'
            response.set_header('Cache-Control', "%s, max-age=%s" % (pragma, seconds))
            response.set_header('Pragma', pragma)
            return callback(*args, **kwargs)
        return wrapper
github mining / mining / mining / controllers / data / __init__.py View on Github external
if "download" in request.GET.keys():

            ext = request.GET.get("download", "xls")
            if ext == '':
                ext = 'xls'

            file_name = '{}/frontend/assets/exports/openmining-{}.{}'.format(
                PROJECT_PATH, element.get('cube'), ext)
            if ext == 'csv':
                df.to_csv(file_name, sep=";")
                contenttype = 'text/csv'
            else:
                df.to_excel(file_name)
                contenttype = 'application/vnd.ms-excel'

            response.set_header('charset', 'utf-8')
            response.set_header('Content-disposition', 'attachment; '
                                'filename={}.{}'.format(
                                    element.get('cube'), ext))
            response.content_type = contenttype

            ifile = open(file_name, "r")
            o = ifile.read()
            ifile.close()

            return o

        return json.dumps(DM.data)
github telstra / open-kilda / services / maxinet / app / maxinet_rest.py View on Github external
def create_experiment():
    try:
        validate(request.json, experiment_schema)
        name = _create_experiment(request.json['name'], request.json['cluster'], request.json['topo'])
        response.content_type = 'application/json'
        response.status = 201
        response.set_header('Location', "http://frontend/experiment/{}".format(name))
        return json.dumps({'name': name})
    except ValidationError as e:
        abort(400, e.message)
github comsysto / github-pages-basic-auth-proxy / cs_proxy / proxy.py View on Github external
def proxy_trough_helper(url):
    print ('PROXY-GET: {0}'.format(url))
    proxy_response = requests.get(url)
    if proxy_response.status_code == 200:
        if proxy_response.headers['Last-Modified']:
            response.set_header('Last-Modified', proxy_response.headers['Last-Modified'])
        if proxy_response.headers['Content-Type']:
            response.set_header('Content-Type',  proxy_response.headers['Content-Type'])
        if proxy_response.headers['Expires']:
            response.set_header('Expires',       proxy_response.headers['Expires'])
        return proxy_response
    else:
        return HTTPResponse(status=proxy_response.status_code,
                            body=template(error_tpl,
                                          headline='Error {0}'.format(proxy_response.status_code),
                                          error='error during proxy call'))