Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement web.run_app utility function #734

Merged
merged 20 commits into from
Jan 13, 2016
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Support ssl scheme
asvetlov committed Jan 6, 2016
commit 2e4e4bb6e0857fe6fbb267a197e020b1be4a402e
16 changes: 10 additions & 6 deletions aiohttp/web.py
Original file line number Diff line number Diff line change
@@ -273,22 +273,26 @@ def __repr__(self):


def run_app(app, *, host='0.0.0.0', port=None, loop=None,
shutdown_timeout=60.0):
shutdown_timeout=60.0, ssl_context=None):
"""Run an app locally"""
if port is None:
# allow to use 8443 if future ssl=True will be added
port = 8080
if not ssl_context:
port = 8080
else:
port = 8443

if loop is None:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is an explicit loop parameter necessary -- Wouldn't loop = app.loop suffice here?
Is there a use case where the App would run on a different loop than the Server?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point!

loop = asyncio.get_event_loop()

handler = app.make_handler()
srv = loop.run_until_complete(loop.create_server(handler, host, port))
srv = loop.run_until_complete(loop.create_server(handler, host, port,
ssl=ssl_context))

scheme = 'https' if ssl_context else 'http'
prompt = '127.0.0.1' if host == '0.0.0.0' else host
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How should someone bind to public interface?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, read from end to top))

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use :: for IPv6 (:

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I don't follow.
Isn't knowledge of host/port info enough?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I already said -- I read diff from bottom to top) thought that you replaced '0.0.0.0' with localhost and bind to it)

print(" * Running on http://{prompt}:{port}/ \n"
print("======== Running on {scheme}://{prompt}:{port}/ ========\n"
"(Press CTRL+C to quit)".format(
host=prompt, port=port))
scheme=scheme, host=prompt, port=port))

try:
loop.run_forever()