diff --git a/AUTHORS b/AUTHORS index 776e791c..e3dd319f 100644 --- a/AUTHORS +++ b/AUTHORS @@ -50,4 +50,5 @@ Patches and Suggestions - Dan Head - Bruno ReniƩ - David Fischer -- Joseph McCullough \ No newline at end of file +- Joseph McCullough +- Juergen Brendel diff --git a/requests/__init__.py b/requests/__init__.py index 027ea3c5..e3a9d2a0 100644 --- a/requests/__init__.py +++ b/requests/__init__.py @@ -24,7 +24,7 @@ __copyright__ = 'Copyright 2011 Kenneth Reitz' from . import utils from .models import Request, Response -from .api import request, get, head, post, patch, put, delete +from .api import request, get, head, post, patch, put, delete, options from .sessions import session, Session from .status_codes import codes from .exceptions import ( diff --git a/requests/api.py b/requests/api.py index bc9fde7e..ff2e3b34 100644 --- a/requests/api.py +++ b/requests/api.py @@ -13,7 +13,7 @@ This module implements the Requests API. from .sessions import session -__all__ = ('request', 'get', 'head', 'post', 'patch', 'put', 'delete') +__all__ = ('request', 'get', 'options', 'head', 'post', 'patch', 'put', 'delete') def request(method, url, @@ -68,6 +68,17 @@ def get(url, **kwargs): return request('GET', url, **kwargs) +def options(url, **kwargs): + """Sends a OPTIONS request. Returns :class:`Response` object. + + :param url: URL for the new :class:`Request` object. + :param **kwargs: Optional arguments that ``request`` takes. + """ + + kwargs.setdefault('allow_redirects', True) + return request('OPTIONS', url, **kwargs) + + def head(url, **kwargs): """Sends a HEAD request. Returns :class:`Response` object. diff --git a/requests/async.py b/requests/async.py index 84abd40d..f413526c 100644 --- a/requests/async.py +++ b/requests/async.py @@ -24,7 +24,7 @@ from .hooks import dispatch_hook __all__ = ( 'map', - 'get', 'head', 'post', 'put', 'patch', 'delete', 'request' + 'get', 'options', 'head', 'post', 'put', 'patch', 'delete', 'request' ) @@ -54,6 +54,7 @@ def send(r, pools=None): # Patched requests.api functions. get = patched(api.get) +options = patched(api.options) head = patched(api.head) post = patched(api.post) put = patched(api.put) diff --git a/requests/sessions.py b/requests/sessions.py index 83bfe129..6f7270bb 100644 --- a/requests/sessions.py +++ b/requests/sessions.py @@ -199,6 +199,17 @@ class Session(object): return self.request('GET', url, **kwargs) + def options(self, url, **kwargs): + """Sends a OPTIONS request. Returns :class:`Response` object. + + :param url: URL for the new :class:`Request` object. + :param **kwargs: Optional arguments that ``request`` takes. + """ + + kwargs.setdefault('allow_redirects', True) + return self.request('OPTIONS', url, **kwargs) + + def head(self, url, **kwargs): """Sends a HEAD request. Returns :class:`Response` object. @@ -257,4 +268,4 @@ class Session(object): def session(**kwargs): """Returns a :class:`Session` for context-management.""" - return Session(**kwargs) \ No newline at end of file + return Session(**kwargs)