Skip to content

Commit

Permalink
Change default User-Agent from Mozilla/5 to python-caldav/$version
Browse files Browse the repository at this point in the history
Resolves #391
  • Loading branch information
tobixen committed Oct 20, 2024
1 parent 6f0bd41 commit 25ee90b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ This project should more or less adhere to [Semantic Versioning](https://semver.
### Changed

* In https://github.com/python-caldav/caldav/pull/366, I optimized the logic in `search` a bit, now all data from the server not containing a VEVENT, VTODO or VJOURNAL will be thrown away. I believe this won't cause any problems for anyone, as the server should only deliver such components, but I may be wrong.
* Default User-Agent changed from `Mozilla/5` to `python-caldav/{__version__}`

### Added

Expand Down
3 changes: 2 additions & 1 deletion caldav/davclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from requests.structures import CaseInsensitiveDict

from .elements.base import BaseElement
from caldav import __version__
from caldav.elements import dav
from caldav.lib import error
from caldav.lib.python_utilities import to_normal_str
Expand Down Expand Up @@ -421,7 +422,7 @@ def __init__(

# Build global headers
self.headers = {
"User-Agent": "Mozilla/5.0",
"User-Agent": "python-caldav/" + __version__,
"Content-Type": "text/xml",
"Accept": "text/xml, text/calendar",
}
Expand Down
15 changes: 15 additions & 0 deletions tests/test_caldav_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ def testRequestNonAscii(self, mocked):
def testRequestCustomHeaders(self, mocked):
"""
ref https://github.com/python-caldav/caldav/issues/285
also ref https://github.com/python-caldav/caldav/issues/385
"""
mocked().status_code = 200
mocked().headers = {}
Expand All @@ -289,6 +290,20 @@ def testRequestCustomHeaders(self, mocked):
## 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 testRequestUserAgent(self, mocked):
"""
ref https://github.com/python-caldav/caldav/issues/391
"""
mocked().status_code = 200
mocked().headers = {}
cal_url = "http://me:[email protected]øøh.example:80/"
client = DAVClient(
url=cal_url,
)
assert client.headers["Content-Type"] == "text/xml"
assert client.headers["User-Agent"].startswith("python-caldav/")

@mock.patch("caldav.davclient.requests.Session.request")
def testEmptyXMLNoContentLength(self, mocked):
"""
Expand Down

0 comments on commit 25ee90b

Please sign in to comment.