Skip to content

Instantly share code, notes, and snippets.

@xlcommunity
Created June 30, 2015 12:15
Show Gist options
  • Save xlcommunity/40190f1f7e03a5920f2e to your computer and use it in GitHub Desktop.
Save xlcommunity/40190f1f7e03a5920f2e to your computer and use it in GitHub Desktop.
HttpRequest modified to support PATCH
# THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS
# FOR A PARTICULAR PURPOSE. THIS CODE AND INFORMATION ARE NOT SUPPORTED BY XEBIALABS.
...
from org.apache.http.client.config import RequestConfig
# HttpPatch added here
from org.apache.http.client.methods import HttpGet, HttpPost, HttpPut, HttpPatch, HttpDelete
...
class HttpRequest:
...
def buildRequest(self, method, context, body, contentType, headers):
url = self.quote(self.createPath(self.params.getUrl(), context))
method = method.upper()
if method == 'GET':
request = HttpGet(url)
elif method == 'POST':
request = HttpPost(url)
request.setEntity(StringEntity(body))
elif method == 'PUT':
request = HttpPut(url)
request.setEntity(StringEntity(body))
# adding this elif clause to support PATCH
elif method == 'PATCH':
request = HttpPatch(url)
request.setEntity(StringEntity(body))
elif method == 'DELETE':
request = HttpDelete(url)
else:
raise Exception('Unsupported method: ' + method)
request.addHeader('Content-Type', contentType)
request.addHeader('Accept', contentType)
self.setCredentials(request)
self.setProxy(request)
self.setHeaders(request, headers)
return request
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment