Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:63220 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 13883 invoked from network); 21 Sep 2012 14:17:25 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 21 Sep 2012 14:17:25 -0000 Authentication-Results: pb1.pair.com header.from=julienpauli@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=julienpauli@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.223.170 as permitted sender) X-PHP-List-Original-Sender: julienpauli@gmail.com X-Host-Fingerprint: 209.85.223.170 mail-ie0-f170.google.com Received: from [209.85.223.170] ([209.85.223.170:33636] helo=mail-ie0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 85/C9-62301-4F67C505 for ; Fri, 21 Sep 2012 10:17:25 -0400 Received: by iebc12 with SMTP id c12so4713877ieb.29 for ; Fri, 21 Sep 2012 07:17:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date :x-google-sender-auth:message-id:subject:to:cc:content-type; bh=tAHlpSIffadWuFLlwb7K5MJMPadLe3HyNFzmmO5rn2c=; b=xFFU0kJAlaZON3T52UoJaVdae11spzQpqG9g87LVuQgT+fjY+wx5cxnkatPWq5zTLF /cI6M6P/ARIiI4H7gscAXTjz04al7x/d7bO3XQPgczEXacoEst55gVpyHqDPWSjF70Jk ZEOesu7EOzrZfO3POCq+MXqOZONjgE/Dscvf840Ojg8KJTjqBOkBNztE9iA+P2qB6eo+ 0IdNNudiVLdJQwFlOE/cip3npC1M/pwbSrivRCd1LoFLSqrw/+p4BjytdZXQqGfODiWB VOxeT47rTQo4Pn7wDManC0PFpvm3Nyo5j4qnQGrr0sY2j9YP2hMf8YbrtOeElDWxhr/r 0LRA== Received: by 10.50.184.196 with SMTP id ew4mr1836791igc.5.1348237042358; Fri, 21 Sep 2012 07:17:22 -0700 (PDT) MIME-Version: 1.0 Sender: julienpauli@gmail.com Received: by 10.64.63.201 with HTTP; Fri, 21 Sep 2012 07:16:42 -0700 (PDT) In-Reply-To: <505C4A06.6040304@hoa-project.net> References: <505C4A06.6040304@hoa-project.net> Date: Fri, 21 Sep 2012 16:16:42 +0200 X-Google-Sender-Auth: 1zAEnQsiymPdJqTc4Mk_g9Ewfgc Message-ID: To: ivan.enderlin@hoa-project.net Cc: internals@lists.php.net Content-Type: text/plain; charset=ISO-8859-1 Subject: Re: [PHP-DEV] POST, content-type: application/json and json_decode From: jpauli@php.net (jpauli) On Fri, Sep 21, 2012 at 1:05 PM, Ivan Enderlin @ Hoa 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