diff options
| author | Tom Christie | 2011-04-11 11:47:22 +0100 |
|---|---|---|
| committer | Tom Christie | 2011-04-11 11:47:22 +0100 |
| commit | 338b5213fa6232dc6115b214495cf13ded6a3a17 (patch) | |
| tree | 6a5b7988e9922004ff5cbfb326f5e5f264ca62b5 /djangorestframework/request.py | |
| parent | 2fe0e584354a6625b0b293aebc7a7820ad50213e (diff) | |
| download | django-rest-framework-338b5213fa6232dc6115b214495cf13ded6a3a17.tar.bz2 | |
More tests passing
Diffstat (limited to 'djangorestframework/request.py')
| -rw-r--r-- | djangorestframework/request.py | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/djangorestframework/request.py b/djangorestframework/request.py index c5d98286..f79354a1 100644 --- a/djangorestframework/request.py +++ b/djangorestframework/request.py @@ -1,4 +1,8 @@ from djangorestframework.mediatypes import MediaType +from djangorestframework.utils import as_tuple +from djangorestframework.response import ResponseException +from djangorestframework import status + #from djangorestframework.requestparsing import parse, load_parser from django.http.multipartparser import LimitBytes from StringIO import StringIO @@ -11,6 +15,8 @@ class RequestMixin(object): CONTENTTYPE_PARAM = "_content_type" CONTENT_PARAM = "_content" + parsers = () + def _get_method(self): """ Returns the HTTP method for the current view. @@ -33,7 +39,10 @@ class RequestMixin(object): """ if not hasattr(self, '_content_type'): content_type = self.request.META.get('HTTP_CONTENT_TYPE', self.request.META.get('CONTENT_TYPE', '')) - self._content_type = MediaType(content_type) + if content_type: + self._content_type = MediaType(content_type) + else: + self._content_type = None return self._content_type @@ -68,8 +77,15 @@ class RequestMixin(object): if not hasattr(self, '_stream'): request = self.request + try: + content_length = int(request.META.get('CONTENT_LENGTH', request.META.get('HTTP_CONTENT_LENGTH'))) + except (ValueError, TypeError): + content_length = 0 + # Currently only supports parsing request body as a stream with 1.3 - if hasattr(request, 'read'): + if content_length == 0: + return None + elif hasattr(request, 'read'): # It's not at all clear if this needs to be byte limited or not. # Maybe I'm just being dumb but it looks to me like there's some issues # with that in Django. @@ -152,6 +168,9 @@ class RequestMixin(object): May raise a 415 ResponseException (Unsupported Media Type), or a 400 ResponseException (Bad Request). """ + if stream is None or content_type is None: + return None + parsers = as_tuple(self.parsers) parser = None |
