diff --git a/CHANGELOG.md b/CHANGELOG.md index bb89a5f..9e045df 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ This project should more or less adhere to [Semantic Versioning](https://semver. * `get_duration`: make sure the algorithm doesn't raise an exception comparing dates with timestamps * `set_due`: make sure the algorithm doesn't raise an exception comparing naive timestamps with timezone timestamps * Code formatting / style fixes. +* Jason Yau introduced the possibility to add arbitrary headers - but things like User-Agent would anyway always be overwritten. Now the custom logic takes precedence. Pull request https://github.com/python-caldav/caldav/pull/386, issue https://github.com/python-caldav/caldav/issues/385 * Search method did some logic handling non-conformant servers (loading data from the server if the search response didn't include the icalendar data, ignoring trash from the Google server when it returns data without a VTODO/VEVENT/VJOURNAL component. * Revisited a problem that Google sometimes delivers junk when doing searches - credits to github user @zhwei in https://github.com/python-caldav/caldav/pull/366 * There were some compatibility-logic loading objects if the server does not deliver icalendar data (as it's suppsoed to do according to the RFC), but only if passing the `expand`-flag to the `search`-method. Fixed that it loads regardless of weather `expand` is set or not. Also in https://github.com/python-caldav/caldav/pull/366 diff --git a/caldav/davclient.py b/caldav/davclient.py index 45d4b68..9284ea1 100644 --- a/caldav/davclient.py +++ b/caldav/davclient.py @@ -409,14 +409,12 @@ def __init__( self.proxy = _proxy # Build global headers - self.headers = headers - self.headers.update( - { - "User-Agent": "Mozilla/5.0", - "Content-Type": "text/xml", - "Accept": "text/xml, text/calendar", - } - ) + self.headers = { + "User-Agent": "Mozilla/5.0", + "Content-Type": "text/xml", + "Accept": "text/xml, text/calendar", + } + self.headers.update(headers) if self.url.username is not None: username = unquote(self.url.username) password = unquote(self.url.password) diff --git a/tests/test_caldav_unit.py b/tests/test_caldav_unit.py index a38e6ab..a4486be 100644 --- a/tests/test_caldav_unit.py +++ b/tests/test_caldav_unit.py @@ -279,9 +279,14 @@ def testRequestCustomHeaders(self, mocked): mocked().status_code = 200 mocked().headers = {} cal_url = "http://me:hunter2@calendar.møøh.example:80/" - client = DAVClient(url=cal_url, headers={"X-NC-CalDAV-Webcal-Caching": "On"}) + client = DAVClient( + url=cal_url, + headers={"X-NC-CalDAV-Webcal-Caching": "On", "User-Agent": "MyCaldavApp"}, + ) assert client.headers["Content-Type"] == "text/xml" assert client.headers["X-NC-CalDAV-Webcal-Caching"] == "On" + ## User-Agent would be overwritten by some boring default in earlier versions + assert client.headers["User-Agent"] == "MyCaldavApp" @mock.patch("caldav.davclient.requests.Session.request") def testEmptyXMLNoContentLength(self, mocked):