From c398be9b5ca200f01c947ad63d337dce4b66af8d Mon Sep 17 00:00:00 2001 From: Athanasius Date: Thu, 5 Aug 2021 17:04:44 +0100 Subject: [PATCH] Contributing: Document `--debug-send ...` code and usage --- Contributing.md | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/Contributing.md b/Contributing.md index 7240195b..50682e64 100644 --- a/Contributing.md +++ b/Contributing.md @@ -225,7 +225,39 @@ Adding `--trace` to a `pytest` invocation causes it to drop into a [`pdb`](https://docs.python.org/3/library/pdb.html) prompt for each test, handy if you want to step through the testing code to be sure of anything. -Otherwise, see the [pytest documentation](https://docs.pytest.org/en/stable/contents.html). +Otherwise, see the [pytest documentation](https://docs.pytest.org/en/stable/contents.html). + +--- +## Debugging network sends + +Rather than risk sending bad data to a remote service, even if only through +repeatedly sending the same data you can cause such code to instead send +through a local web server and thence to a log file. + +1. This utilises the `--debug-sender ...` command-line argument. The argument + to this is free-form, so there's nothing to edit in EDMarketConnector.py + in order to support a new target for this. +2. The debug web server is set up globally in EDMarketConnector.py. +3. In code where you want to utilise this you will need at least something + like this (taken from some plugins/edsm.py code): + +```python +from config import debug_senders +from edmc_data import DEBUG_WEBSERVER_HOST, DEBUG_WEBSERVER_PORT + +TARGET_URL = 'https://www.edsm.net/api-journal-v1' +if 'edsm' in debug_senders: + TARGET_URL = f'http://{DEBUG_WEBSERVER_HOST}:{DEBUG_WEBSERVER_PORT}/edsm' + +... + r = this.session.post(TARGET_URL, data=data, timeout=_TIMEOUT) +``` + + Be sure to set a URL path in the `TARGET_URL` that denotes where the data + would normally be sent to. +4. The output will go into a file in `%TEMP%\EDMarketConnector\http_debug` + whose name is based on the path component of the URL. In the code example + above it will come out as `edsm.log` due to how `TARGET_URL` is set. ---