cherrypy / cherrypy

CherryPy is a pythonic, object-oriented HTTP framework. https://cherrypy.dev
https://docs.cherrypy.dev
BSD 3-Clause "New" or "Revised" License
1.8k stars 357 forks source link

InternalRedirect access logging -> log original request instead of redirected #1994

Open easy-easy opened 1 year ago

easy-easy commented 1 year ago

Hello,

this is a bug/feature request (not sure what exactly matches).

I'm using a default implementation for an online shop using regex for "beautiful urls".

For reroute the request I use the InternalRedirect Exception, which works fine. But at the access log there appears the redirected entry instead of the original one. How can I log the original entry instead?

import cherrypy

class Root:
    @cherrypy.expose
    def default(self, *args, **kwargs):
        print('default')
        raise cherrypy.InternalRedirect('/destination/?p='+'/'.join(args))

    @cherrypy.expose
    def destination(self, p: str = None):
        print(f'destination: {p}')

cherrypy.quickstart(Root())

If I call this with http://localhost/testurl.html the logentry created logs the url: /destination/?p=testurl.html

The output is:

default destination: testurl.html

The accesslog entry:

127.0.0.1 - - [24/Apr/2023:10:21:29] "GET /destination/p=testurl.html HTTP/1.1" 200 - "" "Wget/1.21.3"

I need to log the original url instead in the access log. How can I to this?

Regards, easy.