#36245: Implement Configurable Content Type Parsing `request.data` to Modernize 
the
HTTPRequest
-------------------------------+--------------------------------------
     Reporter:  Adya           |                    Owner:  Adya
         Type:  New feature    |                   Status:  closed
    Component:  HTTP handling  |                  Version:  5.1
     Severity:  Normal         |               Resolution:  duplicate
     Keywords:  parsing, http  |             Triage Stage:  Unreviewed
    Has patch:  0              |      Needs documentation:  0
  Needs tests:  0              |  Patch needs improvement:  0
Easy pickings:  0              |                    UI/UX:  0
-------------------------------+--------------------------------------
Comment (by Adya):

 Replying to [comment:5 Sarah Boyce]:
 > Thank you very much for the comment, I had already checked this ticket,
 maybe there was a confusion .
 I think PR and discussion in ticket
 https://code.djangoproject.com/ticket/21442, It is not active after some
 progress for the last 5 months. And according to Django GSoC Idea page it
 is mentioned that contributors have to accomplish it in **two phases**. So
 I opened a ticket for the initial phase. It is mentioned here
 
https://code.djangoproject.com/wiki/SummerOfCode2025#ConfigurableContentTypeParsing

 But this idea is proposed in Django **GSoC 2025** and I am working on it,
 on the current Django Development version.

 *I am discussing in the Forum too
 https://forum.djangoproject.com/u/adyaprasad/summary*

 **For the Initial phase I have implemented changes in
 `django/http/request.py` and `django/http/response.py`**
 In `django/http/request.py` something like (reference short code)
 {{{
 class HttpRequest:
     # ... existing code ...

     @property
     def data(self):
         """
         Parses and returns the request body based on Content-Type.

         Currently supports:
         * 'application/json': Returns the parsed JSON data
         * All other content types: Returns an empty dictionary
         """
         if not hasattr(self, '_cached_data'):
             content_type = self.headers.get('Content-Type', '')
             # Extract the main content type without parameters
             content_type = content_type.split(';')[0].strip()

             if content_type == 'application/json':
                 if not self.body:
                     self._cached_data = {}
                 else:
                     try:
                         self._cached_data =
 json.loads(self.body.decode('utf-8'))
                     except (ValueError, UnicodeDecodeError) as exc:
                         from django.core.exceptions import BadRequest
                         raise BadRequest(f"JSON parse error - {str(exc)}")
             else:
                 # For the initial phase, return empty dict for non-JSON
 content
                 self._cached_data = {}

         return self._cached_data

 }}}
 I can change the code if need and not fit
 My proposal and research paper are almost ready, I am working on the Test
 Cases

 **Please help me, what should I do now? Either assigned me ticket #21442
 and opened and assigned me this ticket**
 **What would you like to recommend?**
 🤞
-- 
Ticket URL: <https://code.djangoproject.com/ticket/36245#comment:6>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/django-updates/010701958a3342ff-a7f7e418-f121-454c-9717-e5cf2164aee5-000000%40eu-central-1.amazonses.com.

Reply via email to