Skip to content

Commit

Permalink
Merge pull request #74 from jkaving/post-without-data
Browse files Browse the repository at this point in the history
#74 Support POST requests without data in web.py
  • Loading branch information
deanishe committed Feb 27, 2016
2 parents 6e4ae1f + 34f7061 commit 27a8126
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
7 changes: 7 additions & 0 deletions tests/test_web.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,13 @@ def test_post_json(self):
self.assert_(data['json'][key] == self.data[key])
return

def test_post_without_data(self):
"""POST request without data"""
url = BASE_URL + 'post'
r = web.post(url)
self.assert_(r.status_code == 200)
r.raise_for_status()

def test_timeout(self):
"""Request times out"""
url = self.httpbin.url + '/delay/3'
Expand Down
5 changes: 4 additions & 1 deletion workflow/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,6 @@ def request(method, url, params=None, data=None, headers=None, cookies=None,
"""

# TODO: cookies
# TODO: any way to force GET or POST?
socket.setdefaulttimeout(timeout)

# Default handlers
Expand Down Expand Up @@ -542,6 +541,10 @@ def request(method, url, params=None, data=None, headers=None, cookies=None,

headers['accept-encoding'] = ', '.join(encodings)

# Force a POST by providing an empty data string
if method == 'POST' and not data:
data = ''

if files:
if not data:
data = {}
Expand Down

0 comments on commit 27a8126

Please sign in to comment.