Skip to content

Commit

Permalink
fix: logging http requests without query parameters (#631)
Browse files Browse the repository at this point in the history
* fix: logging http requests without query parameters

* docs: update CHANGELOG.md
  • Loading branch information
bednar authored Jan 29, 2024
1 parent d7181fa commit 4f1ab87
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

### Bug Fixes
1. [#562](https://github.com/influxdata/influxdb-client-python/pull/562): Use `ThreadPoolScheduler` for `WriteApi`'s batch subject instead of `TimeoutScheduler` to prevent creating unnecessary threads repeatedly
1. [#631](https://github.com/influxdata/influxdb-client-python/pull/631): Logging HTTP requests without query parameters

## 1.39.0 [2023-12-05]

Expand Down
2 changes: 1 addition & 1 deletion influxdb_client/_sync/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def request(self, method, url, query_params=None, headers=None,
headers['Content-Type'] = 'application/json'

if self.configuration.debug:
_BaseRESTClient.log_request(method, f"{url}?{urlencode(query_params)}")
_BaseRESTClient.log_request(method, f"{url}{'' if query_params is None else '?' + urlencode(query_params)}")
_BaseRESTClient.log_headers(headers, '>>>')
_BaseRESTClient.log_body(body, '>>>')

Expand Down
12 changes: 12 additions & 0 deletions tests/test_InfluxDBClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,18 @@ def test_custom_debug_logging_handler(self):
logger = logging.getLogger('influxdb_client.client.http')
self.assertEqual(2, len(logger.handlers))

def test_debug_request_without_query_parameters(self):
httpretty.register_uri(httpretty.GET, uri="http://localhost/ping", status=200, body="")
self.influxdb_client = InfluxDBClient("http://localhost", "my-token", debug=True)

log_stream = StringIO()
logger = logging.getLogger("influxdb_client.client.http")
logger.addHandler(logging.StreamHandler(log_stream))

self.influxdb_client.api_client.call_api('/ping', 'GET')

self.assertIn("'GET http://localhost/ping'", log_stream.getvalue())


class ServerWithSelfSingedSSL(http.server.SimpleHTTPRequestHandler):
def _set_headers(self, response: bytes):
Expand Down

0 comments on commit 4f1ab87

Please sign in to comment.