Changed existing octoprint.server.http.* hooks to prefix routes with /plugin/<identifier>/
This will hopefully prevent conflicting routes between multiple plugins from being registered and also ensures a more consistent behaviour compared to BlueprintPlugin mixins. Thanks to @Salandora for bringing this up.
This commit is contained in:
parent
3823216319
commit
ceb0e29da3
2 changed files with 25 additions and 4 deletions
|
|
@ -285,6 +285,9 @@ octoprint.server.http.bodysize
|
|||
against which to match as first, a regular expression for the path to match against and the maximum body size as
|
||||
an integer as the third entry.
|
||||
|
||||
The path of the route will be prefixed by OctoPrint with ``/plugin/<plugin identifier>/`` (if the path already begins
|
||||
with a ``/`` that will be stripped first).
|
||||
|
||||
**Example**
|
||||
|
||||
The following plugin example sets the maximum body size for ``POST`` requests against four custom URLs to 100, 200,
|
||||
|
|
@ -320,6 +323,18 @@ octoprint.server.http.routes
|
|||
class to use for the route as the second and a dictionary with keywords parameters for the defined request handler as
|
||||
the third entry.
|
||||
|
||||
The path of the route will be prefixed by OctoPrint with ``/plugin/<plugin identifier>/`` (if the path already begins
|
||||
with a ``/`` that will be stripped first).
|
||||
|
||||
.. note::
|
||||
|
||||
Static routes provided through this hook take precedence over routes defined through blueprints.
|
||||
|
||||
If your plugin also implements the :class:`~octoprint.plugin.BlueprintPlugin` mixin and has defined a route for a
|
||||
view on that which matches one of the paths provided via its ``octoprint.server.http.routes`` hook handler, the
|
||||
view of the blueprint will thus not be reachable since processing of the request will directly be handed over
|
||||
to your defined handler class.
|
||||
|
||||
**Example**
|
||||
|
||||
The following example registers two new routes ``/plugin/add_tornado_route/download`` and ``/plugin/add_tornado_route/forward``
|
||||
|
|
|
|||
|
|
@ -785,8 +785,11 @@ class Server():
|
|||
if not isinstance(entry[2], dict):
|
||||
continue
|
||||
|
||||
self._logger.debug("Adding additional route {route} handled by handler {handler} and with additional arguments {args!r}".format(route=entry[0], handler=entry[1], args=entry[2]))
|
||||
server_routes.append(entry)
|
||||
route, handler, kwargs = entry
|
||||
route = r"/plugin/{name}/{route}".format(name=name, route=route if not route.startswith("/") else route[1:])
|
||||
|
||||
self._logger.debug("Adding additional route {route} handled by handler {handler} and with additional arguments {kwargs!r}".format(**locals()))
|
||||
server_routes.append((route, handler, kwargs))
|
||||
|
||||
server_routes.append((r".*", util.tornado.UploadStorageFallbackHandler, dict(fallback=util.tornado.WsgiInputContainer(app.wsgi_app), file_prefix="octoprint-file-upload-", file_suffix=".tmp", suffixes=upload_suffixes)))
|
||||
|
||||
|
|
@ -811,8 +814,11 @@ class Server():
|
|||
if not isinstance(entry[2], int):
|
||||
continue
|
||||
|
||||
self._logger.debug("Adding maximum body size of {size}B for {method} requests to {path} (Plugin: {name})".format(method=entry[0], path=entry[1], size=entry[2], name=name))
|
||||
max_body_sizes.append(entry)
|
||||
method, route, size = entry
|
||||
route = r"/plugin/{name}/{route}".format(name=name, route=route if not route.startswith("/") else route[1:])
|
||||
|
||||
self._logger.debug("Adding maximum body size of {size}B for {method} requests to {route})".format(**locals()))
|
||||
max_body_sizes.append((method, route, size))
|
||||
|
||||
self._server = util.tornado.CustomHTTPServer(self._tornado_app, max_body_sizes=max_body_sizes, default_max_body_size=settings().getInt(["server", "maxSize"]))
|
||||
self._server.listen(self._port, address=self._host)
|
||||
|
|
|
|||
Loading…
Reference in a new issue