Skip to content

Commit 10da972

Browse files
committed
Specify correct Content-Type header for 1.x servers.
1 parent fb1d935 commit 10da972

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

77
## [Unreleased]
8+
### Fixed
9+
- Specify correct Content-Type header for 1.x servers.
810

911
## [1.0.0-beta.2] -- 2021-07-20
1012
### Changed

farmOS/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,11 @@ def __init__(
100100
# Unset the 'expires_at' key.
101101
token.pop("expires_at")
102102

103+
# Determine the Content-Type header depending on server version.
104+
content_type = (
105+
"application/vnd.api+json" if version == 2 else "application/json"
106+
)
107+
103108
# Create an OAuth Session
104109
self.session = OAuthSession(
105110
hostname=hostname,
@@ -108,6 +113,7 @@ def __init__(
108113
scope=scope,
109114
token=token,
110115
token_url=token_url,
116+
content_type=content_type,
111117
token_updater=self.token_updater,
112118
)
113119

farmOS/session.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ def __init__(
1919
token=None,
2020
token_url=None,
2121
authorization_url=None,
22+
content_type="application/vnd.api+json",
2223
token_updater=None,
2324
*args,
2425
**kwargs,
@@ -44,6 +45,7 @@ def __init__(
4445
# Save values for later use.
4546
self._token_url = token_url
4647
self._authorization_base_url = authorization_url
48+
self._content_type = content_type
4749
self._client_id = client_id
4850
self._client_secret = client_secret
4951
self.hostname = hostname
@@ -128,14 +130,14 @@ def _http_request(self, url, method="GET", options=None, params=None, headers=No
128130
data = None
129131
if options and "data" in options:
130132
data = options["data"]
131-
headers["Content-Type"] = "application/vnd.api+json"
133+
headers["Content-Type"] = self._content_type
132134

133135
# If there is a json data to be sent, include it.
134136
json = None
135137
if options and "json" in options:
136138
json = options["json"]
137139
if "Content-Type" not in headers:
138-
headers["Content-Type"] = "application/vnd.api+json"
140+
headers["Content-Type"] = self._content_type
139141

140142
# Perform the request.
141143
response = self.request(

0 commit comments

Comments
 (0)