Skip to content

Commit

Permalink
Only json.dumps in request() if content is json-serializable
Browse files Browse the repository at this point in the history
  • Loading branch information
tulir committed May 11, 2019
1 parent 21bb087 commit 5bd6fe6
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion mautrix_appservice/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
from .state_store import StateStore
from .intent_api import IntentAPI

__version__ = "0.3.8"
__version__ = "0.3.9"
__author__ = "Tulir Asokan <[email protected]>"
5 changes: 3 additions & 2 deletions mautrix_appservice/intent_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,10 @@ def request(self, method: str, path: str, content: Optional[Union[dict, bytes, s
if method not in ["GET", "PUT", "DELETE", "POST"]:
raise MatrixError("Unsupported HTTP method: %s" % method)

if "Content-Type" not in headers:
is_json_ish = isinstance(content, (dict, list, str, int, float, bool, type(None)))
if "Content-Type" not in headers and is_json_ish:
headers["Content-Type"] = "application/json"
if headers.get("Content-Type", None) == "application/json":
if headers.get("Content-Type", None) == "application/json" and is_json_ish:
content = json.dumps(content)

if self.identity and not self.is_real_user:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setuptools.setup(
name="mautrix-appservice",
version="0.3.8",
version="0.3.9",
url="https://github.com/tulir/mautrix-appservice-python",

author="Tulir Asokan",
Expand Down

0 comments on commit 5bd6fe6

Please sign in to comment.