Skip to content

Commit

Permalink
Add PATCH method to pycurl request
Browse files Browse the repository at this point in the history
  • Loading branch information
lerrua committed Dec 15, 2015
1 parent ebc7ada commit fdbbc38
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion pyresttest/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
# Kind of obnoxious that it works this way...
HTTP_METHODS = {u'GET': pycurl.HTTPGET,
u'PUT': pycurl.UPLOAD,
u'PATCH': pycurl.POSTFIELDS,
u'POST': pycurl.POST,
u'DELETE': 'DELETE'}

Expand Down Expand Up @@ -275,9 +276,17 @@ def configure_curl(self, timeout=DEFAULT_TIMEOUT, context=None, curl_handle=None
curl.setopt(pycurl.INFILESIZE, len(bod))
else:
curl.setopt(pycurl.INFILESIZE, 0)
elif self.method == u'PATCH':
curl.setopt(curl.POSTFIELDS, bod)
curl.setopt(curl.CUSTOMREQUEST, 'PATCH')
# Required for some servers
if bod is not None:
curl.setopt(pycurl.INFILESIZE, len(bod))
else:
curl.setopt(pycurl.INFILESIZE, 0)
elif self.method == u'DELETE':
curl.setopt(curl.CUSTOMREQUEST, 'DELETE')
elif self.method and self.method.upper() != 'GET': # Support PATCH/HEAD/ETC
elif self.method and self.method.upper() != 'GET': # Support HEAD/ETC
curl.setopt(curl.CUSTOMREQUEST, self.method.upper())

head = self.get_headers(context=context)
Expand Down

0 comments on commit fdbbc38

Please sign in to comment.