Discussion:
[bottlepy] Access to raw path in bottle
Andy Salnikov
2015-07-01 17:56:34 UTC
Permalink
Hi, I have an interesting problem when trying to migrate our old code to
bottle.

Basically we have some REST-like interface for one of our services with API
which looks like this (in bottle-route speak):

GET /service/<resource>
GET /service/<resource>/<node:path>
- plus bunch of other methods


This was implemented in pure wsgiref but now I'd like to simplify it a bit
and re-implement with bottle. One major complication here is that we
discovered late in the game that resource name may have embedded slashes in
them. To workaround that we require from client side every resource name
sent to server being quoted including slash character being replaced with
%2F. On server side we parse still quoted path name and extract resource
name from it and unquote it.

This approach does not work well with bottle. First it looks like routing
is using unquoted path which of course confuses our rules. I thought I
would use more generic rule like:
GET/service/<res_and_node:path>

and then parse path myself, but that needs an access to raw unquoted path
as it comes from client and bottle does not seem to provide this facility.
I tried all possible attributes of request instance, but all of them return
path with %2F replaced with slash. It looks like bottle does unquote and
then quote if you want to see the path, which may not be the same as the
original path.

Is there any way in bottle to get access to the path that client sent?

Thanks,
Andy
--
--
You are member of the "bottlepy" group at google groups.
See http://groups.google.de/group/bottlepy for mailing list options.
See http://bottlepy.org/ for news and documentation.

---
You received this message because you are subscribed to the Google Groups "bottlepy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bottlepy+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Marcel Hellkamp
2015-07-01 18:50:15 UTC
Permalink
Bottle and request.path as well as the routing engine all use the
unmodified value of environ['PATH_INFO'] which is the only source of
information available to a WSGI application. If that value is already
translated, then the http server implementation did that prior to
calling into bottle.

You can check for the (non-standard) request.environ["REQUEST_URI"]
string that may contain the untranslated version of the complete request
string including the query part.
Post by Andy Salnikov
Hi, I have an interesting problem when trying to migrate our old code to
bottle.
Basically we have some REST-like interface for one of our services with
|
GET /service/<resource>
GET /service/<resource>/<node:path>
-plus bunch of other methods
|
This was implemented in pure wsgiref but now I'd like to simplify it a
bit and re-implement with bottle. One major complication here is that we
discovered late in the game that resource name may have embedded slashes
in them. To workaround that we require from client side every resource
name sent to server being quoted including slash character being
replaced with %2F. On server side we parse still quoted path name and
extract resource name from it and unquote it.
This approach does not work well with bottle. First it looks like
routing is using unquoted path which of course confuses our rules. I
|
GET/service/<res_and_node:path>
|
and then parse path myself, but that needs an access to raw unquoted
path as it comes from client and bottle does not seem to provide this
facility. I tried all possible attributes of request instance, but all
of them return path with %2F replaced with slash. It looks like bottle
does unquote and then quote if you want to see the path, which may not
be the same as the original path.
Is there any way in bottle to get access to the path that client sent?
Thanks,
Andy
--
--
You are member of the "bottlepy" group at google groups.
See http://groups.google.de/group/bottlepy for mailing list options.
See http://bottlepy.org/ for news and documentation.
---
You received this message because you are subscribed to the Google Groups "bottlepy" group.
To unsubscribe from this group and stop receiving emails from it, send
For more options, visit https://groups.google.com/d/optout.
--
--
You are member of the "bottlepy" group at google groups.
See http://groups.google.de/group/bottlepy for mailing list options.
See http://bottlepy.org/ for news and documentation.

---
You received this message because you are subscribed to the Google Groups "bottlepy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bottlepy+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Andy Salnikov
2015-07-02 16:27:07 UTC
Permalink
Hi Marcel,

you are right, sorry for the noise. I believe it is wsgiref/simple_server
that does
unquoting before addong PATH_INFO to environment. For production we use
flup SCGI server, and for testing new bottle port I decided to run it with
wsgiref.
This probably explains the difference in handling quoted stuff in URI.

Thanks,
Andy
Post by Marcel Hellkamp
Bottle and request.path as well as the routing engine all use the
unmodified value of environ['PATH_INFO'] which is the only source of
information available to a WSGI application. If that value is already
translated, then the http server implementation did that prior to
calling into bottle.
You can check for the (non-standard) request.environ["REQUEST_URI"]
string that may contain the untranslated version of the complete request
string including the query part.
--
--
You are member of the "bottlepy" group at google groups.
See http://groups.google.de/group/bottlepy for mailing list options.
See http://bottlepy.org/ for news and documentation.

---
You received this message because you are subscribed to the Google Groups "bottlepy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bottlepy+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...