misc: add setting to define string substitutions on HTTP responses (#73805) #63

Merged
bdauvergne merged 2 commits from wip/73805-settings-REQUESTS-SUBSTITUTION-p into main 2023-01-31 16:09:04 +01:00

2 Commits

Author SHA1 Message Date
Benjamin Dauvergne 738709aa9c misc: use the same content-types list for logging and substitutions (#738050 2023-01-31 16:08:18 +01:00
Benjamin Dauvergne 41b013a1d2 misc: add setting to define string substitutions on HTTP responses (#73805)
settings.CONNECTORS_SETTINGS = {
         'cmis/test': {
           'requests_substitutions': [
	     {
	       'url': 'https://service.example.com/api/',
	       'search': 'http://service.example.internal/software/api/',
	       'replace': 'https://service.example.com/api/'
	     }
           ]
         }
	}

CONNECTORS_SETTINGS is a new setting to contain any setting pertaining
to a specific connector, it's a dictionnary of dictionnaries indexed by
connectors identifier constructed from the appname and the connector's
slug.

requests_substitutions is the first defined key in this dictionnary,
it's a list of dictionnaries:
* substitution is only done on the following content-types:
  text/*, application/(.*\+)?json, application/(.*\+)?xml
* default list of content-types can be changed through the
  REQUESTS_SUBSTITUTIONS_CONTENT_TYPES setting.
* scheme and netloc are strictly matched, path must be a prefix or empty
* search is a python regular expression
* url is optionnal, and restrict the substitution to URLs with the same
  prefix,
* replace is a replacement string for reb.sub()
* for json, structural replacement is implemented, if eventually
  escaping is used.
2023-01-31 16:08:14 +01:00