Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:108777 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 57354 invoked from network); 26 Feb 2020 21:54:26 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 26 Feb 2020 21:54:26 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 1678E18054E for ; Wed, 26 Feb 2020 12:12:10 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-wm1-f51.google.com (mail-wm1-f51.google.com [209.85.128.51]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Wed, 26 Feb 2020 12:12:09 -0800 (PST) Received: by mail-wm1-f51.google.com with SMTP id p17so703150wma.1 for ; Wed, 26 Feb 2020 12:12:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding:content-language; bh=Si8G782LSpsi/j2ml/RpLpim0raSpXUt9m8+KKQAW0E=; b=EQLaldl6FEHRQasAnL3wFOzSJhr5GfDgI4Svkiwykt3Ks1ClB6+xJ9o6Qqp7sbffp6 IsuE3+Yueg+cw5xzrw3FH7AUKXgGMsbJJJJmunyRQaP4p8Hnmr5u5ro5tDonIO0bf5/W n9Gh1sIsitZJAtJGErYuwv2C8VIu8Q4VhFCwzRNzuz9JJVpEPyMYSs+I1Aapyct+bAH+ RNVOgRUyd2lgiUz/6v1IXC3H14fs5+wE4ID0cbjopf/Osbans1FRhsbolcBpxOf0B3C5 /YKts3jJGsa8bC5TUolr5DJ7hDYL96/OL6lamggWV5mNJyeSbZKgd2OhjgYmoOx1eYy3 nawg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=Si8G782LSpsi/j2ml/RpLpim0raSpXUt9m8+KKQAW0E=; b=GVqM4mGSKbF2tbUSeP34UhVbAg17bOEEd4+hUNbq3PF9NXUSkvdPaOh1vmX4/Ill2z Kug/V/pBTasgvt65izRbrSx/U7eOMaYmcczoY2YepNcQwEBdzB+CWQml8gwsMtifv2TQ jzTMDNGBj4fRqLMPf6VEtJ9btiimldZIhLH4nodbjQnrjkegVZpoza8btSut4XQhTOMi E/18ak8Pwqp0RIdHBG6rMX7zKHxivM/4JKFndvXB6VZ3nH9n02JvPmY64OYVGs2m2AE3 KTTJ9gvc3eJoxC+3EOXpc/MCKrjcED9lyRC8aLKLExao9W6cuYnlNq7BLJLoQwOU50bG 2syw== X-Gm-Message-State: APjAAAX0nz6Dz3eWqbaMQsa5WG4Y+bY/Un9pm+FCSfxZTYMk/YTRd9lq VrSEC1QYElGm8k4K5DbdztqNXlUx X-Google-Smtp-Source: APXvYqx2AE8SrD2xAl3XPJoDQJZDLr5GPG6EWOgC6gO1mQ8IReix44iHmOdNoDBP9zwcxvL0ojsTJg== X-Received: by 2002:a1c:5419:: with SMTP id i25mr600484wmb.150.1582747925876; Wed, 26 Feb 2020 12:12:05 -0800 (PST) Received: from [192.168.0.14] (cpc84253-brig22-2-0-cust114.3-3.cable.virginm.net. [81.108.141.115]) by smtp.googlemail.com with ESMTPSA id e16sm4846404wrc.48.2020.02.26.12.12.04 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 26 Feb 2020 12:12:04 -0800 (PST) To: php internals References: <50BD013E-CF72-414C-BBC0-A7A2E45CBDDB@pmjones.io> <5904137.fSVIMsojiJ@mcmic-probook> <3DDBFBA4-8D3A-46C5-9A10-B093A5E2386B@pmjones.io> <54493258-B52E-442A-A11D-82E1D4C7DE5E@gmail.com> <8264F6CF-AD55-41E2-9F5A-DAE8942E2B79@pmjones.io> <1BF3D29A-04C6-4A82-9216-EAE991A38916@pmjones.io> <10388b3a-3402-a6dc-3837-b03d735edf46@gmail.com> <5ec7b4a7-508b-270b-916f-0504a116196c@gmail.com> <30112AFF-38F9-44D4-9D2F-03A32019764F@pmjones.io> Message-ID: Date: Wed, 26 Feb 2020 20:12:00 +0000 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-GB Subject: Re: [PHP-DEV] RFC: Server-Side Request and Response Objects (v2) From: rowan.collins@gmail.com (Rowan Tommins) On 26/02/2020 19:57, Paul M. Jones wrote: > I'm sorry, I'm still having trouble seeing what you're getting at. Do you mean something like this in the ServerRequest constructor? > > public function __construct(array $globals, ?string $content = null) > { > if ( > ($globals['_POST'] ?? null) === null > && > strtolower($globals['_SERVER']['CONTENT_TYPE']) === 'application/x-www-form-urlencoded' > ) { > if ($content === null) { > $content = file_get_contents('php://input'); > } > $globals['_POST'] = []; > parse_str($content, $globals['_POST']); > } > > // ... > } That's the easy part, yes; the harder part is this: if ( ($globals['_POST'] ?? null) === null && strtolower($globals['_SERVER']['CONTENT_TYPE']) === 'multipart/form-data' ) { if ($content === null) { $content = file_get_contents('php://input'); } [ $globals['_POST'], $globals['_FILE'] ] = parse_multipart_form_data($content); } Where parse_multipart_form_data is a function which doesn't currently exist, but whose logic must all be there in the core somewhere, because everything shows up in $_POST and $_FILES when you process such a request. Recreating that functionality in userland is non-trivial, but is essential for several use cases, e.g. an event-based server like ReactPHP, or a test using a saved request body as a fixture. If both content types (application/x-www-form-urlencoded and multipart/form-data) were handled, it would also mean that the relationship $content -> $input would match the relationship php://input -> $_POST by default, which seems consistent with the aim of matching existing behaviour. Regards, -- Rowan Tommins (né Collins) [IMSoP]