Clean up querystring logic.
This commit is contained in:
parent
ffcbaf366e
commit
8b278eb05d
14 changed files with 66 additions and 35 deletions
|
|
@ -26,7 +26,7 @@ class BaseResponse(object):
|
|||
for key, value in request.form.iteritems():
|
||||
querystring[key] = [value, ]
|
||||
|
||||
if querystring is None:
|
||||
if not querystring:
|
||||
querystring.update(parse_qs(urlparse(full_url).query))
|
||||
if not querystring:
|
||||
querystring.update(parse_qs(self.body))
|
||||
|
|
|
|||
|
|
@ -20,12 +20,16 @@ class DomainDispatcherApplication(object):
|
|||
value. We'll match the host header value with the url_bases of each backend.
|
||||
"""
|
||||
|
||||
def __init__(self, create_app):
|
||||
def __init__(self, create_app, service=None):
|
||||
self.create_app = create_app
|
||||
self.lock = Lock()
|
||||
self.app_instances = {}
|
||||
self.service = service
|
||||
|
||||
def get_backend_for_host(self, host):
|
||||
if self.service:
|
||||
return BACKENDS[self.service]
|
||||
|
||||
for backend in BACKENDS.itervalues():
|
||||
for url_base in backend.url_bases:
|
||||
if re.match(url_base, 'http://%s' % host):
|
||||
|
|
@ -55,7 +59,7 @@ class RegexConverter(BaseConverter):
|
|||
self.regex = items[0]
|
||||
|
||||
|
||||
def create_backend_app(backend):
|
||||
def create_backend_app(service):
|
||||
from werkzeug.routing import Map
|
||||
|
||||
# Create the backend_app
|
||||
|
|
@ -66,6 +70,8 @@ def create_backend_app(backend):
|
|||
backend_app.view_functions = {}
|
||||
backend_app.url_map = Map()
|
||||
backend_app.url_map.converters['regex'] = RegexConverter
|
||||
|
||||
backend = BACKENDS[service]
|
||||
for url_path, handler in backend.flask_paths.iteritems():
|
||||
backend_app.route(url_path, methods=HTTP_METHODS)(convert_flask_to_httpretty_response(handler))
|
||||
|
||||
|
|
@ -74,6 +80,9 @@ def create_backend_app(backend):
|
|||
|
||||
def main(argv=sys.argv[1:]):
|
||||
parser = argparse.ArgumentParser()
|
||||
|
||||
# Keep this for backwards compat
|
||||
parser.add_argument("service", type=str)
|
||||
parser.add_argument(
|
||||
'-H', '--host', type=str,
|
||||
help='Which host to bind',
|
||||
|
|
@ -86,7 +95,7 @@ def main(argv=sys.argv[1:]):
|
|||
args = parser.parse_args(argv)
|
||||
|
||||
# Wrap the main application
|
||||
main_app = DomainDispatcherApplication(create_backend_app)
|
||||
main_app = DomainDispatcherApplication(create_backend_app, service=args.service)
|
||||
main_app.debug = True
|
||||
|
||||
run_simple(args.host, args.port, main_app)
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
from .responses import QueueResponse, QueuesResponse
|
||||
|
||||
url_bases = [
|
||||
"https?://queue(.*).amazonaws.com"
|
||||
"https?://(.*?)(queue|sqs)(.*?).amazonaws.com"
|
||||
]
|
||||
|
||||
url_paths = {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue