Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CHange default User-Agent from Mozilla/5 to python-caldav/$version #392

Merged
merged 1 commit into from
Oct 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading