On Fri, Sep 21, 2012 at 1:05 PM, Ivan Enderlin @ Hoa <ivan.ender...@hoa-project.net> wrote: > Hello, > > If PHP receives a HTTP request with the method POST and with the header > Content-Type: application/x-www-form-encoded, then, it automatically parses > the request body to populate an array in $_POST. If the Content-Type is > different (e.g. text/plain or application/json), the request body is > reachable by reading php://input. Well, it is ok. > > But is there any plans to consider application/json by parsing the request > body and populate the result in $_POST (with the help of json_decode() > maybe)? > > If so, I would like to propose a patch but I don't find in the source code > where request body is caugth and parsed (for POST). Any ideas? > Maybe a RFC would also be welcome to complete my suggestion? > > Thanks.
Hi ! Reading and parsing post data function is defined as a SAPI struct function pointer. You should look at sapi_module_struct definition (http://lxr.php.net/xref/PHP_5_4/main/SAPI.h#251). When a request comes in, sapi_activate() is called. It then calls sapi_read_post_data() http://lxr.php.net/xref/PHP_5_4/main/SAPI.c#459 that itself invokes handlers. Default handlers are defined here : http://lxr.php.net/xref/PHP_5_4/main/php_content_types.c#29 and for POST, by default, sapi_read_standard_form_data() is called (defined here http://lxr.php.net/xref/PHP_5_4/main/SAPI.c#253) This function is in fact just a bridge, it tells PHP to call sapi.read_post() which is a function pointer defined by each SAPI. Finally, later on, sapi.default_post_reader() is called (again, a function pointer defined by each SAPI) I agree it's not a very trivial part though :p Julien.P -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php