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

Send Content-Type only if there is data, relative post location #32

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
@@ -1 +1,3 @@
docs/_build/*
*.pyc
*~
18 changes: 14 additions & 4 deletions slumber/__init__.py
Expand Up @@ -98,7 +98,12 @@ def _request(self, method, data=None, params=None):
if self._store["append_slash"] and not url.endswith("/"):
url = url + "/"

resp = self._store["session"].request(method, url, data=data, params=params, headers={"content-type": s.get_content_type(), "accept": s.get_content_type()})
headers = {"accept": s.get_content_type()}

if data is not None:
headers["content-type"] = s.get_content_type()

resp = self._store["session"].request(method, url, data=data, params=params, headers=headers)

if 400 <= resp.status_code <= 499:
raise exceptions.HttpClientError("Client Error %s: %s" % (resp.status_code, url), response=resp, content=resp.content)
Expand All @@ -124,12 +129,17 @@ def post(self, data, **kwargs):

resp = self._request("POST", data=s.dumps(data), params=kwargs)
if 200 <= resp.status_code <= 299:
if resp.status_code == 201:
location = resp.headers.get("location")
if resp.status_code == 201 and location is not None:
# @@@ Hacky, see description in __call__
resource_obj = self(url_override=resp.headers["location"])
if location.startswith("/"):
resource_obj = self(id=location)
else:
resource_obj = self(url_override=location)
return resource_obj.get(params=kwargs)
else:
return resp.content
if resp.content:
return self.get_serializer().loads(resp.content)
else:
# @@@ Need to be Some sort of Error Here or Something
return
Expand Down