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

Sanic routing #2010

Merged
merged 33 commits into from
Feb 16, 2021
Merged

Sanic routing #2010

merged 33 commits into from
Feb 16, 2021

Conversation

ahopkins
Copy link
Member

@ahopkins ahopkins commented Jan 27, 2021

Implementation of sanic-routing. Currently, it is written as a dependency. Whether it stays that way or is merged into this repo is up for discussion at a later date.

Besides overhauling the Router to use the compiled version, this also hits the following:

  • Resolve bug with middleware in Blueprint Group when passed callable
  • Moves common logic between Blueprint and Sanic into mixins
  • Will likely touch on some consistency with naming of routes, I am divided on this but if we are going to break it, then we should do it now
  • Some new convenience decorators:
    • @app.before_server_start
    • @app.after_server_start
    • @app.before_server_stop
    • @app.after_server_stop
    • @app.on_request
    • @app.on_response
  • fixes Allow header that did not include HEAD
  • using "name" keyword in url_for for a "static" route where name does not exist
  • Cannot have multiple app.static() without using the named param
  • using "filename" keyword in url_for on a file route
  • request endpoint is the route name, should mark that as deprecated
  • route names are fully namespaced
  • no handler type name prefixes (static, websocket, etc)
  • unquote in route def (not automatic)
  • routes_all is tuples
  • handler arguments are kwarg only
  • request.match_info is now a cached (and not computed) property
  • unknown static file mimetype is sent as application/octet-stream
  • _host keyword in url_for
  • add charset default to utf-8 for text and js content types if not specified
  • versionfor a route can be str, float, or int
  • route has ctx property
  • app has routes_static, routes_dynamic, routes_regex
  • Websocket subprotocol support #874

See discussion

@ahopkins ahopkins added this to the v21.3 milestone Jan 27, 2021
@ahopkins
Copy link
Member Author

This pull request has been mentioned on Sanic Community Discussion. There might be relevant details there:

https://community.sanicframework.org/t/a-fast-new-router/649/38

@ahopkins ahopkins marked this pull request as draft January 27, 2021 08:34
@ahopkins ahopkins mentioned this pull request Jan 28, 2021
@ashleysommer
Copy link
Member

Looking great!

@ahopkins
Copy link
Member Author

Requires: sanic-org/sanic-testing#13

@ahopkins
Copy link
Member Author

@ahopkins ahopkins marked this pull request as ready for review February 15, 2021 08:47
@codecov
Copy link

codecov bot commented Feb 15, 2021

Codecov Report

Merging #2010 (bb5501f) into master (d3cbcf0) will increase coverage by 0.68%.
The diff coverage is 95.25%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2010      +/-   ##
==========================================
+ Coverage   91.45%   92.13%   +0.68%     
==========================================
  Files          28       33       +5     
  Lines        3171     3104      -67     
  Branches      571      542      -29     
==========================================
- Hits         2900     2860      -40     
+ Misses        192      165      -27     
  Partials       79       79              
Impacted Files Coverage Δ
sanic/compat.py 100.00% <ø> (+17.64%) ⬆️
sanic/utils.py 73.33% <ø> (+47.80%) ⬆️
sanic/views.py 97.67% <50.00%> (-2.33%) ⬇️
sanic/router.py 92.10% <92.75%> (-4.04%) ⬇️
sanic/mixins/routes.py 93.93% <93.93%> (ø)
sanic/app.py 91.96% <94.01%> (-2.96%) ⬇️
sanic/asgi.py 94.96% <100.00%> (+0.03%) ⬆️
sanic/base.py 100.00% <100.00%> (ø)
sanic/blueprint_group.py 100.00% <100.00%> (ø)
sanic/blueprints.py 100.00% <100.00%> (+4.63%) ⬆️
... and 15 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d3cbcf0...bb5501f. Read the comment docs.

@ahopkins
Copy link
Member Author

Passing tests except for Python 3.6 with uvloop. See #2024

@ahopkins
Copy link
Member Author

Fixes #1671

@ahopkins ahopkins linked an issue Feb 15, 2021 that may be closed by this pull request
@ahopkins ahopkins requested a review from a team February 16, 2021 00:11
Copy link
Member

@ashleysommer ashleysommer left a comment

Choose a reason for hiding this comment

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

Looking great

@ahopkins ahopkins merged commit 8f8c00a into master Feb 16, 2021
@ahopkins ahopkins deleted the sanic-routing branch February 16, 2021 08:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Content-Type
2 participants