diff --git a/epio.ini b/epio.ini index c3f81c0..a78cd0c 100644 --- a/epio.ini +++ b/epio.ini @@ -2,13 +2,3 @@ entrypoint = httpbin:app requirements = reqs.txt - - -[services] - -redis = true - - -[env] - -HTTPBIN_LOG_REQUESTS = true \ No newline at end of file diff --git a/httpbin/core.py b/httpbin/core.py index efe657b..1dce34c 100644 --- a/httpbin/core.py +++ b/httpbin/core.py @@ -12,48 +12,18 @@ import json import gzip import os from cStringIO import StringIO -from time import time as now from decimal import Decimal +from time import time as now -import redi from decorator import decorator from flask import Flask, Response, request, render_template, redirect, g -from .db import redis_connect from .helpers import get_files, get_headers, status_code app = Flask(__name__) -# ------ -# Config -# ------ - -def logging_is_enabled(): - """Returns bool to determine if logging is enabled or not.""" - - return os.environ.get('HTTPBIN_LOG_REQUESTS', False) - - - -# -------------- -# Pre-Processing -# -------------- - -if logging_is_enabled: - - @app.before_request - def db_connect(): - """Connects Redis to g object.""" - - # redis connect - if not getattr(g, 'r', None): - g.r = redis_connect() - redi.config.init(r=g.r) - - - # -------------- # Output Filters # -------------- @@ -108,26 +78,6 @@ def gzip_response(f, *args, **kwargs): - - -def log_request(key): - """Logging Decorator.""" - - def log_request(f, *args, **kwargs): - - response = f(*args, **kwargs) - - if logging_is_enabled(): - # store request in redis list - redi.s.httplib._(key, 'list').append(response) - - return response - - return decorator(log_request) - - - - # ------ # Routes # ------ @@ -141,7 +91,6 @@ def view_landing_page(): @app.route('/ip') @json_resource -@log_request(key='httpbin:ip') def view_origin(): """Returns Origin IP.""" @@ -150,7 +99,6 @@ def view_origin(): @app.route('/headers') @json_resource -@log_request(key='httpbin:headers') def view_headers(): """Returns HTTP HEADERS.""" @@ -161,7 +109,6 @@ def view_headers(): @app.route('/user-agent') @json_resource -@log_request(key='httpbin:user-agent') def view_user_agent(): """Returns User-Agent.""" @@ -172,7 +119,6 @@ def view_user_agent(): @app.route('/get', methods=('GET',)) @json_resource -@log_request(key='httpbin:get') def view_get(): """Returns GET Data.""" @@ -187,7 +133,6 @@ def view_get(): @app.route('/post', methods=('POST',)) @json_resource -@log_request(key='httpbin:post') def view_post(): """Returns POST Data.""" @@ -204,7 +149,6 @@ def view_post(): @app.route('/put', methods=('PUT',)) @json_resource -@log_request(key='httpbin:put') def view_post(): """Returns PUT Data.""" @@ -221,7 +165,6 @@ def view_post(): @app.route('/delete', methods=('DELETE',)) @json_resource -@log_request(key='httpbin:delete') def view_post(): """Returns DETLETE Data.""" @@ -239,7 +182,6 @@ def view_post(): @app.route('/gzip') @gzip_response @json_resource -@log_request(key='httpbin:gzip') def view_gzip_encoded_content(): """Returns GZip-Encoded Data.""" diff --git a/httpbin/db.py b/httpbin/db.py deleted file mode 100644 index f3b4baa..0000000 --- a/httpbin/db.py +++ /dev/null @@ -1,33 +0,0 @@ -# -*- coding: utf-8 -*- - -""" -dashboard.db -~~~~~~~~~~~~ - -This module provides the Dashboard database interface. - -""" - -from redis import Redis - - -__all__ = ('redis_connect',) - - - -def redis_connect(): - """Connect to appropriate Redis system. Returns Redis instance. """ - - try: - # ep.io configuration - from bundle_config import config - r = Redis( - host = config['redis']['host'], - port = int(config['redis']['port']), - password = config['redis']['password'], - ) - except ImportError: - # TODO: use local settings (env?) - r = Redis(host='localhost', port=6379, db=0) - - return r \ No newline at end of file diff --git a/reqs.txt b/reqs.txt index 335b7c7..5c6a2a0 100644 --- a/reqs.txt +++ b/reqs.txt @@ -5,6 +5,4 @@ Werkzeug==0.6.2 argparse==1.2.1 distribute==0.6.15 wsgiref==0.1.2 -decorator==3.3.1 -redi==0.0.8b -redis==2.4.5 \ No newline at end of file +decorator==3.3.1 \ No newline at end of file