예제 #1
0
def basic_auth(user='******', passwd='passwd'):
    """Prompts the user for authorization using HTTP Basic Auth."""

    if not check_basic_auth(user, passwd):
        return status_code(401)

    return jsonify(authenticated=True, user=user)
예제 #2
0
파일: core.py 프로젝트: BiYiTuan/devops-2
def cache():
    """Returns a 304 if an If-Modified-Since header or If-None-Match is present. Returns the same as a GET otherwise."""
    is_conditional = request.headers.get(
        'If-Modified-Since') or request.headers.get('If-None-Match')
    if is_conditional is None:
        response = view_get()
        response.headers['Last-Modified'] = http_date()
        response.headers['ETag'] = uuid.uuid4().hex
        return response
    else:
        return status_code(304)
예제 #3
0
파일: core.py 프로젝트: BiYiTuan/devops-2
def view_status_code(codes):
    """Return status code or random status code if more than one are given"""

    if ',' not in codes:
        code = int(codes)
        return status_code(code)

    choices = []
    for choice in codes.split(','):
        print choice
        if ':' not in choice:
            code = choice
            weight = 1
        else:
            code, weight = choice.split(':')
        choices.append((int(code), float(weight)))

    code = weighted_choice(choices)
    print code
    return status_code(code)
def view_status_code(codes):
    """Return status code or random status code if more than one are given"""
    if ',' not in codes:
        try:
            code = int(codes)
        except ValueError:
            return Response('Invalid status code', status=400)
        return status_code(code)

    choices = []
    for choice in codes.split(','):
        if ':' not in choice:
            code = choice
            weight = 1
        else:
            code, weight = choice.split(':')
        try:
            choices.append((int(code), float(weight)))
        except ValueError:
            return Response('Invalid status code', status=400)

    code = weighted_choice(choices)

    return status_code(code)
예제 #5
0
def image():
    """Returns a simple image of the type suggest by the Accept header."""

    headers = get_headers()
    if 'accept' not in headers:
        return image_png()  # Default media type to png

    accept = headers['accept'].lower()

    if 'image/webp' in accept:
        return image_webp()
    elif 'image/svg+xml' in accept:
        return image_svg()
    elif 'image/jpeg' in accept:
        return image_jpeg()
    elif 'image/png' in accept or 'image/*' in accept:
        return image_png()
    else:
        return status_code(406)  # Unsupported media type
예제 #6
0
파일: core.py 프로젝트: BiYiTuan/devops-2
def image():
    """Returns a simple image of the type suggest by the Accept header."""

    headers = get_headers()
    print headers
    if "accept" not in headers:
        return redirect('/image/png')  # Default media type to png

    accept = headers['accept'].lower()
    print accept
    # image_type = ['image/webp', 'image/svg+xml', 'image/jpeg', 'image/png']
    if 'image/webp' in accept:
        return redirect('/image/webp')
    elif 'image/svg+xml' in accept:
        return redirect('/image/svg')
    elif 'image/jpeg' in accept:
        return redirect('/image/jpeg')
    elif 'image/png' in accept:
        return redirect('/image/png')
    else:
        return status_code(406)  # Unsupported media type