示例#1
0
def response_formated_records(recids, collection, of, **kwargs):
    """Return formatter records.

    Response contains correct Cache and TTL information in HTTP headers.
    """
    from invenio.modules.formatter import (get_output_format_content_type,
                                           print_records)
    response = make_response(
        print_records(recids, collection=collection, of=of, **kwargs))
    response.mimetype = get_output_format_content_type(of)
    current_time = datetime.datetime.now()
    response.headers['Last-Modified'] = http_date(
        time.mktime(current_time.timetuple()))
    expires = current_app.config.get('CFG_WEBSEARCH_SEARCH_CACHE_TIMEOUT',
                                     None)

    if expires is None:
        response.headers['Cache-Control'] = (
            'no-store, no-cache, must-revalidate, '
            'post-check=0, pre-check=0, max-age=0')
        response.headers['Expires'] = '-1'
    else:
        expires_time = current_time + datetime.timedelta(seconds=expires)
        response.headers['Vary'] = 'Accept'
        response.headers['Cache-Control'] = ('public' if current_user.is_guest
                                             else 'private')
        response.headers['Expires'] = http_date(
            time.mktime(expires_time.timetuple()))
    return response
示例#2
0
def response_formated_records(recids, collection, of, **kwargs):
    """Return formatter records.

    Response contains correct Cache and TTL information in HTTP headers.
    """
    from invenio.modules.formatter import (get_output_format_content_type,
                                           print_records)
    response = make_response(print_records(recids, collection=collection,
                                           of=of, **kwargs))
    response.mimetype = get_output_format_content_type(of)
    current_time = datetime.datetime.now()
    response.headers['Last-Modified'] = http_date(
        time.mktime(current_time.timetuple())
    )
    expires = current_app.config.get(
        'CFG_WEBSEARCH_SEARCH_CACHE_TIMEOUT', None)

    if expires is None:
        response.headers['Cache-Control'] = (
            'no-store, no-cache, must-revalidate, '
            'post-check=0, pre-check=0, max-age=0'
        )
        response.headers['Expires'] = '-1'
    else:
        expires_time = current_time + datetime.timedelta(seconds=expires)
        response.headers['Vary'] = 'Accept'
        response.headers['Cache-Control'] = (
            'public' if current_user.is_guest else 'private'
        )
        response.headers['Expires'] = http_date(time.mktime(
            expires_time.timetuple()
        ))
    return response
示例#3
0
def response_formated_records(recids, collection, of, **kwargs):
    """TODO."""
    from invenio.modules.formatter import (get_output_format_content_type,
                                           print_records)
    response = make_response(
        print_records(recids, collection=collection, of=of, **kwargs))
    response.mimetype = get_output_format_content_type(of)
    return response
示例#4
0
def response_formated_records(recids, collection, of, **kwargs):
    """TODO."""
    from invenio.modules.formatter import (get_output_format_content_type,
                                           print_records)
    response = make_response(print_records(recids, collection=collection,
                                           of=of, **kwargs))
    response.mimetype = get_output_format_content_type(of)
    return response