Skip to content

Commit

Permalink
User-Agent should be possible to modify - see also #385
Browse files Browse the repository at this point in the history
  • Loading branch information
tobixen committed Apr 13, 2024
1 parent 0b9f91a commit d3d56ad
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 6 additions & 8 deletions caldav/davclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 6 additions & 1 deletion tests/test_caldav_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,9 +279,14 @@ def testRequestCustomHeaders(self, mocked):
mocked().status_code = 200
mocked().headers = {}
cal_url = "http://me:[email protected]øø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):
Expand Down

0 comments on commit d3d56ad

Please sign in to comment.