http://hg.code.sf.net:8000/p/roundup/code/atom-log/tip/roundup/cgi/wsgi_handler.py Mercurial Repository: p/roundup/code: roundup/cgi/wsgi_handler.py history 2026-04-06T22:10:23-04:00 feat: improve store_trace_reason with extract parameter http://hg.code.sf.net:8000/p/roundup/code/#changeset-f80c566f5726c55c8654ec24a9f73a138b2c8a6f John Rouillard rouilj@ieee.org 2026-04-06T22:10:23-04:00 2026-04-06T22:10:23-04:00
changeset f80c566f5726
branch
bookmark
tag
user John Rouillard <rouilj@ieee.org>
description feat: improve store_trace_reason with extract parameter

store_trace_reason() used embedded code to extract reason based on the
location passed to the function.

This change adds support for extract keyword that is a Python
expression eval'ed when the underlying function/method is called. All
callers now set the extract parameter. The prior embedded code has
been removed from store_trace_reason().

Failure to eval the expression results in an roundup.logcontext error
severity log. Also updated docs.

Also replaced env['REQUEST_URI'] with env['PATH_INFO'] for web based
entry points as REQUEST_URI isn't documented as a required key and
some other front end (e.g. zope, cgi) might not supply this.
files
feat: add nanoid pkg trace_id gen and decorator for setting processName http://hg.code.sf.net:8000/p/roundup/code/#changeset-b09ef85f0da62646efe031ee76934ee9b158ae07 John Rouillard rouilj@ieee.org 2025-12-08T00:23:14-05:00 2025-12-08T00:23:14-05:00
changeset b09ef85f0da6
branch
bookmark
tag
user John Rouillard <rouilj@ieee.org>
description feat: add nanoid pkg trace_id gen and decorator for setting processName

nanoid is a shorter unique id generator and faster than uuid.
I truncate nanoid id's to 12 chars to make it more readable.

Also added decorator to allow setting the default processName
definition in the logging module. admin.py and wsgi_handler now set
processName. configuration.py knows how to overide the processName if
set to the default MainProcess.

Updated install docs to add nanoid as optional, how to switch to
different trace_id output. pydoc generated docs include logcontext
module and are referenced from admin.py.
files
refactor: replace boolean expr with named function call http://hg.code.sf.net:8000/p/roundup/code/#changeset-617d55f1d518d66d0d824150212b764df0c72b46 John Rouillard rouilj@ieee.org 2025-10-11T18:18:54-04:00 2025-10-11T18:18:54-04:00
changeset 617d55f1d518
branch
bookmark
tag
user John Rouillard <rouilj@ieee.org>
description refactor: replace boolean expr with named function call

Replace a confusing boolean expression with a the use_cached_tracker()
method call.
files
feature: add thread local trace_id and trace_reason to logging. http://hg.code.sf.net:8000/p/roundup/code/#changeset-14c7c07b32d846e405260147a3112e8c8b15642a John Rouillard rouilj@ieee.org 2025-09-16T22:53:00-04:00 2025-09-16T22:53:00-04:00
changeset 14c7c07b32d8
branch
bookmark
tag
user John Rouillard <rouilj@ieee.org>
description feature: add thread local trace_id and trace_reason to logging.

Added trace_id to default logging so that all logs for a given request
share the same trace_id.

This allows correlation of logs across a request.

admin_guide.txt, upgrading.txt:
add docs
update sample configs to include trace_id.
rewrite logging docs in admin_guide. Hopefully they are clearer now.
clean up some stuff in the logging config file docs.

admin.py:

add decorators to run_command to enable trace_id.
change calls to db.commit() to use run_command to get trace_id.

configuration.py:

clean up imports.
update docstrings, comments and inline docs.
add trace_id to default log format.
add function for testing decorated with trace_id.
add support for dumping stack trace in logging.
add check for pytest in sys.modules to enable log propagation when
pytest is running. Otherwise tests fail as the caplog logger doesn't
see the roundup logs.

logcontext.py:

new file to handle thread local contextvar mangement.

mailgw.py:

add decorators for trace_id etc.

scripts/roundup_xlmrpc_server.py:

add decorators for trace_id etc.
fix encoding bug turning bytes into a string.
fix command line issue where we can't set encoding. (not sure if
changing encoding via command line even works)

cgi/client.py

decorate two entry points for trace_id etc.

cgi/wsgi_handler.py:

decorate entry point for trace_id etc.

test/test_config.py:

add test for trace_id in new log format.
test various cases for sinfo and errors in formating msg.
files
chore(lint): _ unused var; replace assert wth if/raise; whitespace http://hg.code.sf.net:8000/p/roundup/code/#changeset-dbeb6bf056c72c7c489bd07f03ac0663f3e747f3 John Rouillard rouilj@ieee.org 2024-03-24T15:29:55-04:00 2024-03-24T15:29:55-04:00
changeset dbeb6bf056c7
branch
bookmark
tag
user John Rouillard <rouilj@ieee.org>
description chore(lint): _ unused var; replace assert wth if/raise; whitespace
files
chore(lint): fix imports, normalize trailing , on list/tuple http://hg.code.sf.net:8000/p/roundup/code/#changeset-da4c51effdfd4f7cb2a92a4d3535c16f59fd5e6c John Rouillard rouilj@ieee.org 2024-03-20T17:18:52-04:00 2024-03-20T17:18:52-04:00
changeset da4c51effdfd
branch
bookmark
tag
user John Rouillard <rouilj@ieee.org>
description chore(lint): fix imports, normalize trailing , on list/tuple
files
issue2551212 - enable wsgi cache_tracker by default http://hg.code.sf.net:8000/p/roundup/code/#changeset-0fe2b9f6e19f4186cb5752ba1936e2b990cb20ae John Rouillard rouilj@ieee.org 2024-03-20T17:13:30-04:00 2024-03-20T17:13:30-04:00
changeset 0fe2b9f6e19f
branch
bookmark
tag
user John Rouillard <rouilj@ieee.org>
description issue2551212 - enable wsgi cache_tracker by default

Switch the code so the wsgi cache_tracker optimization is enabled by
default. Leave the unoptimized/uncached code path available in case it
breaks something. The feature flag can be set to False to disable
caching.

Updated tests to test the disabled (non-cache) code path.

Updated upgrading.txt with info on how to disable caching.
files
fix(api): - issue2551063 - Rest/Xmlrpc interfaces needs failed login protection. http://hg.code.sf.net:8000/p/roundup/code/#changeset-273c8c2b504245a937efbd42604f77cb2d3d0d9d John Rouillard rouilj@ieee.org 2023-07-19T20:37:45-04:00 2023-07-19T20:37:45-04:00
changeset 273c8c2b5042
branch
bookmark
tag
user John Rouillard <rouilj@ieee.org>
description fix(api): - issue2551063 - Rest/Xmlrpc interfaces needs failed login protection.

Failed API login rate limiting with expiring lockout added.
files
flake8 fixes: whitespace, remove unused imports http://hg.code.sf.net:8000/p/roundup/code/#changeset-07ce4e4110f587bf6a878f9c15a9cb22537969ed John Rouillard rouilj@ieee.org 2023-03-18T14:16:31-04:00 2023-03-18T14:16:31-04:00
changeset 07ce4e4110f5
branch
bookmark
tag
user John Rouillard <rouilj@ieee.org>
description flake8 fixes: whitespace, remove unused imports
files
wsgi can cache tracker instance enabled by feature flag. http://hg.code.sf.net:8000/p/roundup/code/#changeset-d32d43e4a5babf1b398d31c3a091262c0d54bd0a John Rouillard rouilj@ieee.org 2022-07-02T14:04:00-04:00 2022-07-02T14:04:00-04:00
changeset d32d43e4a5ba
branch
bookmark
tag
user John Rouillard <rouilj@ieee.org>
description wsgi can cache tracker instance enabled by feature flag.

Patch by Marcus Priesch caches a loaded tracker instance and reuse it
for future client sessions.

It is enabled by a feature flag in wsgi.py since it arrived during the
2.2.0 beta period.

The provided wsgi.py is modified to enable it. Testing is run with
flag enabled and disabled.

Ralf Schlatterbeck and Marcus tested it on one of their larger more
complex trackers and it sped up the response time to a client request
by a factor of 3 (270ms down to about 80-85ms).
files
Remove Connection: close header for 501 error handling rest http://hg.code.sf.net:8000/p/roundup/code/#changeset-0da655d1498dfa9322325f58d5e9c07f3b36f7ff John Rouillard rouilj@ieee.org 2021-04-26T12:17:15-04:00 2021-04-26T12:17:15-04:00
changeset 0da655d1498d
branch
bookmark
tag
user John Rouillard <rouilj@ieee.org>
description Remove Connection: close header for 501 error handling rest

Ralf doesn't know why the "Connection: close" header was added. Was
there since the original code to support OPTIONS verb was added.
He agrees it can be removed.

Enable test for that code path.

Commit the code not just the test....
files
Factor preloading into a preload method http://hg.code.sf.net:8000/p/roundup/code/#changeset-0343b6fea4b99f4b000bbd7d40bd0af5a7513f85 Ralf Schlatterbeck rsc@runtux.com 2021-02-12T18:46:27+01:00 2021-02-12T18:46:27+01:00
changeset 0343b6fea4b9
branch
bookmark
tag
user Ralf Schlatterbeck <rsc@runtux.com>
description Factor preloading into a preload method
files
Pre-load imports and templates for wsgi http://hg.code.sf.net:8000/p/roundup/code/#changeset-979cecdb70f80aea8fb9c617c552ec7f0d1f8190 Ralf Schlatterbeck rsc@runtux.com 2021-02-03T17:53:55+01:00 2021-02-03T17:53:55+01:00
changeset 979cecdb70f8
branch
bookmark
tag
user Ralf Schlatterbeck <rsc@runtux.com>
description Pre-load imports and templates for wsgi

This triggers preloading once in __init__ doing essentially the same
thing as in __call__. This avoids burdening the first request with the
startup cost. Fixes issue2551112.
Thanks to Robert Klonner for the patch.
files
reworked WSGI interface to not use the RequestDispatcher class for two http://hg.code.sf.net:8000/p/roundup/code/#changeset-3cba8949bfe0bca08c19f68e7b7d35061ff19b43 Christof Meerwald cmeerw@cmeerw.org 2020-02-08T09:56:04+00:00 2020-02-08T09:56:04+00:00
changeset 3cba8949bfe0
branch
bookmark
tag
user Christof Meerwald <cmeerw@cmeerw.org>
description reworked WSGI interface to not use the RequestDispatcher class for two
different purposes (but have a separate RequestHandler)
files
issue2551019 needs to be handled in the action code itself, not the WSGI handler http://hg.code.sf.net:8000/p/roundup/code/#changeset-f74d078cfd9adbeb3164545dedeff0602fdfa973 Christof Meerwald cmeerw@cmeerw.org 2020-02-08T00:29:13+00:00 2020-02-08T00:29:13+00:00
changeset f74d078cfd9a
branch
bookmark
tag
user Christof Meerwald <cmeerw@cmeerw.org>
description issue2551019 needs to be handled in the action code itself, not the WSGI handler
for Python 3 we always need to encode the output in the client character set
files
factor out get_tracker so we can potentially customise if we want to reuse http://hg.code.sf.net:8000/p/roundup/code/#changeset-274c2c082f68b7d4069b7e22368077aad40e0531 Christof Meerwald cmeerw@cmeerw.org 2020-02-05T19:43:57+00:00 2020-02-05T19:43:57+00:00
changeset 274c2c082f68
branch
bookmark
tag
user Christof Meerwald <cmeerw@cmeerw.org>
description factor out get_tracker so we can potentially customise if we want to reuse
tracker instances or create a new instance for each request
files
Flake8 whitespace changes, removal of unused import cgi. http://hg.code.sf.net:8000/p/roundup/code/#changeset-82816000aef36d22d5376385485675aa39227fa9 John Rouillard rouilj@ieee.org 2020-01-17T20:25:39-05:00 2020-01-17T20:25:39-05:00
changeset 82816000aef3
branch
bookmark
tag
user John Rouillard <rouilj@ieee.org>
description Flake8 whitespace changes, removal of unused import cgi.
files
issue2551047: Fix crashes in DELETE, OPTIONS, PATCH http://hg.code.sf.net:8000/p/roundup/code/#changeset-40f5b20d1e70b741b3036719ee9eaff5cb65baed John Rouillard rouilj@ieee.org 2019-10-22T23:36:10-04:00 2019-10-22T23:36:10-04:00
changeset 40f5b20d1e70
branch
bookmark
tag
user John Rouillard <rouilj@ieee.org>
description issue2551047: Fix crashes in DELETE, OPTIONS, PATCH

The wsgi handler parses the form data.

This is a partial patch that fixes some crashes and allows OPTIONS to
be passed through the system. Before it was rejected with a 501 error.

Other modes (cgi, roundup-server) use the code in the __init__method
of the Client class in client.py to parse the input form. The Client
code has been modified to parse and pass json input data. I think
these changes have to be included in the wsgi handler as well.
files
Fix problem with cgi.escape being depricated a different way. This way http://hg.code.sf.net:8000/p/roundup/code/#changeset-883c9e90b4031a477a710c08c8686e18ba47fdbc John Rouillard rouilj@ieee.org 2019-07-06T13:12:58-04:00 2019-07-06T13:12:58-04:00
changeset 883c9e90b403
branch
bookmark
tag
user John Rouillard <rouilj@ieee.org>
description Fix problem with cgi.escape being depricated a different way. This way
uses anypy and is cleaner. Also fixes incorrect/incomplete change that
resulted in escaped in TAL generated by TALInterpreter.py. The escaped
quotes break javascript etc. defined using tal string: values.

TODO: add test cases for TAL. This wouldn't have snuck through for a
month if we had good coverage of that library.
files
Make REST-API updates work with WSGI http://hg.code.sf.net:8000/p/roundup/code/#changeset-edd9e2c67785f97b41b83d01e178f96bc3668b3a Ralf Schlatterbeck rsc@runtux.com 2019-06-23T14:46:05+02:00 2019-06-23T14:46:05+02:00
changeset edd9e2c67785
branch
bookmark
tag
user Ralf Schlatterbeck <rsc@runtux.com>
description Make REST-API updates work with WSGI

Now the Content-Type header is handled specially, it doesn't have a
HTTP_ prefix in WSGI. Also make some form lookups more robust in rest.
files
Fix REST API for WSGI http://hg.code.sf.net:8000/p/roundup/code/#changeset-e7b30ab60941d9e9be3466765f74fee0012250d4 Ralf Schlatterbeck rsc@runtux.com 2019-06-21T18:17:42+02:00 2019-06-21T18:17:42+02:00
changeset e7b30ab60941
branch
bookmark
tag
user Ralf Schlatterbeck <rsc@runtux.com>
description Fix REST API for WSGI

Add dictionary-like headers attribute.
Similar to the apache implementation in same directory but we look up
the given header in the wsgi environment. Environment entries are
mangled (all uppercase, '-' replaced with '_', prefix HTTP_). So on
lookup we mangle the given name first. This allows the rest
implementation (and others) to look up headers.
files
Call cgi.escape only on python 2. Replace with html.escapeif it can be http://hg.code.sf.net:8000/p/roundup/code/#changeset-1a835db4167402cc9a2fdf5eb4345b83b9e64607 John Rouillard rouilj@ieee.org 2019-06-11T21:29:24-04:00 2019-06-11T21:29:24-04:00
changeset 1a835db41674
branch
bookmark
tag
user John Rouillard <rouilj@ieee.org>
description Call cgi.escape only on python 2. Replace with html.escapeif it can be
found.
files
[maint-1.6] Fix fix XSS issue in wsgi and cgi when handing url not found/404. issue2551035 http://hg.code.sf.net:8000/p/roundup/code/#changeset-ab37c1705dbf2a0bbf7acfd7aff64ea6f59fe292 John Rouillard rouilj@ieee.org 2019-03-22T18:16:11-04:00 2019-03-22T18:16:11-04:00
changeset ab37c1705dbf
branch maint-1.6
bookmark
tag
user John Rouillard <rouilj@ieee.org>
description Fix fix XSS issue in wsgi and cgi when handing url not found/404. issue2551035
files
Fix fix XSS issue in wsgi and cgi when handing url not found/404. issue2551035 http://hg.code.sf.net:8000/p/roundup/code/#changeset-5579fa034f9e1dd99a6c760922aa8cd08a9e6559 John Rouillard rouilj@ieee.org 2019-03-22T18:16:11-04:00 2019-03-22T18:16:11-04:00
changeset 5579fa034f9e
branch
bookmark
tag
user John Rouillard <rouilj@ieee.org>
description Fix fix XSS issue in wsgi and cgi when handing url not found/404. issue2551035
files
Fix CSV export with WSGI and Python 3 (issue2551019). http://hg.code.sf.net:8000/p/roundup/code/#changeset-dccf9b7e5ee4350721116287e962d2ee561ecf06 Tom Ekberg tekberg@uw.edu 2019-02-10T14:10:55+00:00 2019-02-10T14:10:55+00:00
changeset dccf9b7e5ee4
branch
bookmark
tag
user Tom Ekberg <tekberg@uw.edu>
description Fix CSV export with WSGI and Python 3 (issue2551019).
files
Handle string-to-bytes conversions for Python 3 for wsgi_handler. http://hg.code.sf.net:8000/p/roundup/code/#changeset-3a07c57d72bbc145057cdd84edb3f59f1abc4555 Joseph Myers jsm@polyomino.org.uk 2018-09-15T20:29:31+00:00 2018-09-15T20:29:31+00:00
changeset 3a07c57d72bb
branch
bookmark
tag
user Joseph Myers <jsm@polyomino.org.uk>
description Handle string-to-bytes conversions for Python 3 for wsgi_handler.
files
Python 3 preparation: update BaseHTTPServer imports. http://hg.code.sf.net:8000/p/roundup/code/#changeset-277e91bf79362587cf409ed0baf37f33c999fcd4 Joseph Myers jsm@polyomino.org.uk 2018-07-25T00:17:07+00:00 2018-07-25T00:17:07+00:00
changeset 277e91bf7936
branch
bookmark
tag
user Joseph Myers <jsm@polyomino.org.uk>
description Python 3 preparation: update BaseHTTPServer imports.

roundup/anypy/http_.py extended and used in more places. Manual
patch.
files
Python 3 preparation: "raise" syntax. http://hg.code.sf.net:8000/p/roundup/code/#changeset-35ea9b1efc1494f29fb07690e7087686de58e0f3 Joseph Myers jsm@polyomino.org.uk 2018-07-24T21:39:58+00:00 2018-07-24T21:39:58+00:00
changeset 35ea9b1efc14
branch
bookmark
tag
user Joseph Myers <jsm@polyomino.org.uk>
description Python 3 preparation: "raise" syntax.

Changing "raise Exception, value" to "raise Exception(value)".
Tool-assisted patch. Particular cases to check carefully are the one
place in frontends/ZRoundup/ZRoundup.py where a string exception
needed to be fixed, and the one in roundup/cgi/client.py involving
raising an exception with a traceback (requires three-argument form of
raise in Python 2, which as I understand it requires exec() to avoid a
Python 3 syntax error).
files
[routing] Remove PATH_INFO hacks that strip leading slash http://hg.code.sf.net:8000/p/roundup/code/#changeset-92757447dcf06c2e356680c8a296075f506ccb46 anatoly techtonik techtonik@gmail.com 2014-07-16T03:10:02+03:00 2014-07-16T03:10:02+03:00
changeset 92757447dcf0
branch routing
bookmark
tag
user anatoly techtonik <techtonik@gmail.com>
description Remove PATH_INFO hacks that strip leading slash

PATH_INFO should always start with '/' when not empty, see
http://tools.ietf.org/html/rfc3875#section-4.1.5
Instead, do leading slash stripping inside cgi.client
files
Fix WSGI response code (thanks Peter Pöml) http://hg.code.sf.net:8000/p/roundup/code/#changeset-7aa72c31464d73b0d015865cf4c82c71d559aa50 Richard Jones richard@users.sourceforge.net 2009-12-11T22:08:23+00:00 2009-12-11T22:08:23+00:00
changeset 7aa72c31464d
branch
bookmark
tag
user Richard Jones <richard@users.sourceforge.net>
description Fix WSGI response code (thanks Peter Pöml)
files
Handle OPTIONS http request method in wsgi handler, fixes issue2550587. http://hg.code.sf.net:8000/p/roundup/code/#changeset-859ab007829f08444edea5f317ec504ed1f16449 Ralf Schlatterbeck schlatterbeck@users.sourceforge.net 2009-12-01T09:09:11+00:00 2009-12-01T09:09:11+00:00
changeset 859ab007829f
branch
bookmark
tag
user Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
description Handle OPTIONS http request method in wsgi handler, fixes issue2550587.

Thanks to Thomas Arendsen Hein for reporting and to Intevation for
funding the fix.
files
make WSGI threadsafe http://hg.code.sf.net:8000/p/roundup/code/#changeset-0728808fdf5c47ff0a5ae8d5eb1b2fd83435e344 Richard Jones richard@users.sourceforge.net 2008-08-18T05:09:00+00:00 2008-08-18T05:09:00+00:00
changeset 0728808fdf5c
branch
bookmark
tag
user Richard Jones <richard@users.sourceforge.net>
description make WSGI threadsafe
files
WSGI support via roundup.cgi.wsgi_handler http://hg.code.sf.net:8000/p/roundup/code/#changeset-a2d22d0de0bc9f47f294ea6b456403ea90051e3a Richard Jones richard@users.sourceforge.net 2006-11-09T00:36:21+00:00 2006-11-09T00:36:21+00:00
changeset a2d22d0de0bc
branch
bookmark
tag
user Richard Jones <richard@users.sourceforge.net>
description WSGI support via roundup.cgi.wsgi_handler
files